#pragma GCC optimize("Ofast") #include using namespace std; typedef long long ll; #define EPS (1e-7) #define INF (1e9) #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define all(x) x.begin(),x.end() const double PI = acos(-1); const ll MOD = 1000000007; template inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } /////////////////////////////////////////////////////////////// int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; string S; cin >> S; int count = 0; string T = ""; rep(i,N) { if (S[i] == '1' || S[i] == '9') T += S[i]; else count++; } int M = T.size(); int cnt1 = 0; int cnt9 = 0; for (int i = M-1; i >= 0; i--) { if (T[i] == '9') cnt9++; else if (cnt9 > 0) { cnt9--; count++; } else { cnt1++; } } while (cnt9 > 1 && cnt1 > 0) { count++; cnt9 -= 2; cnt1--; } count += (cnt1/2); cout << count << endl; }