//89%,不知道哪里有坑。。。
public static void main(String args[]){
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
int[] array = new int[n];
int a = 0,b = 0,result = 0;
for(int i = 0 ; i < n ; ++i){
array[i] = cin.nextInt();
if(array[i] == 1) a++;
else if(array[i] == 2) b++;
}
for(int i = 0 ; i < a ; ++i){
if(array[i] != 1) result++;
}
for(int i = a ; i < a + b ; ++i){
if(array[i] == 3) result++;
}
System.out.println(result);
}
import java.util.Scanner;
public class Solution {
/**
* @param args
*/
static int sum = 0;
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int n = in.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = in.nextInt();
}
int lo = 0;
int hi = n - 1;
quick(arr, lo, hi);
System.out.println(sum);
}
}
public static void quick(int[] arr, int lo, int hi) {
if (hi <= lo) {
return;
}
int lt = lo;
int i = lo + 1;
int gt = hi;
int tmp = arr[lo];
while (i <= gt) {
if (arr[i] < tmp) {
swap(arr, lt++, i++);
} else if (arr[i] > tmp) {
swap(arr, i, gt--);
} else {
i++;
}
}
quick(arr, lo, lt - 1);
quick(arr, gt + 1, hi);
}
public static void swap(int[] a, int i, int j) {
if (a[i] != a[j])
sum++;
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
} 三向切分快排,不知道好不好使