ok
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 5;
int a[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, cnt0 = 0, cnt2 = 0, k = 0, t = 0, k2 = 0, t0 = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] == 0)
cnt0++;
if (a[i] == 2)
cnt2++;
}
for (int i = 1; i <= cnt0; i++) {
if (a[i] != 0) {
k++;
}
if (a[i] == 2)
k2++;
}
for (int i = n - cnt2 + 1; i <= n; i++) {
if (a[i] != 2) {
t++;
}
if (a[i] == 0)
t0++;
}
cout << k + t - min(k2, t0);
return 0;
}