#include <iostream>
#include <vector>
#include <algorithm>
int main(){
int n;
std::cin >> n;
std::vector<int> candies(n);
for (int k = 0; k < n; ++k)
std::cin >> candies[k];
// count total number of 1s, 2s, 3s
int sum1 = 0, sum2 = 0, sum3 = 0;
for (int k = 0; k < n; ++k){
if (candies[k] == 1)
sum1++;
else if (candies[k] == 2)
sum2++;
else
sum3++;
}
// all 3s should be placed in the range [sum1+sum2, n-1]
// and then leave a subproblem of 1s and 2s in the range [0, sum1+sum2-1]
int swap = 0;
std::vector<int> temp_queue;
for (int k = sum1 + sum2; k < n; ++k){
if (candies[k] != 3){
swap++;
temp_queue.push_back(candies[k]);
}
}
// move all 1s to the front and 2s to the end
std::sort(temp_queue.begin(), temp_queue.end());
// in [0, sum1+sum2-1], we want to put 1s to the front and 2s to the end
for (int k = sum1 + sum2 - 1; k >= 0; --k){
if (candies[k] == 3){
candies[k] = temp_queue.back();
temp_queue.pop_back();
}
}
// finally, count how many 2s are still there in the range [0, sum1-1]
// which is supposed to be all 1s
for (int k = 0; k < sum1; ++k){
if (candies[k] == 2)
swap++;
}
std::cout << swap << std::endl;
return 0;
}