#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { int n; string s; cin >> n >> s; int ans = 0; int co = 0, co1 = 0; for (int i = n - 1; i >= 0; i--) { if (s[i] != '1' && s[i] != '9') { ans++; } else if (s[i] == '9') { co++; } else { if (co != 0) { co--; ans++; } else { co1++; } } } ans += min(co / 4, co1); co1 -= min(co / 4, co1); cout << ans + co1 / 2 << endl; }