#include using namespace std; int main() { ios::sync_with_stdio(false); int N; cin >> N; string S; cin >> S; vector cnt(10); for (char c : S) ++cnt[c - '0']; int ans = 0; for (int p : { 3, 5, 7 }) ans += cnt[p]; vector onepos; for (int i = 0; i < N; ++i) { if (S[i] == '1') { onepos.push_back(i); } } for (int i = N - 1; ~i; --i) { if (S[i] != '9') continue; while (onepos.size() && i < onepos.back()) { onepos.pop_back(); } if (onepos.size()) { assert(onepos.back() < i); onepos.pop_back(); --cnt[1]; ++ans; } } ans += cnt[1] / 2; cout << ans << endl; return 0; }