MOD = 10 ** 9 + 7 INF = 10 ** 10 import sys sys.setrecursionlimit(100000000) dy = (-1,0,1,0) dx = (0,1,0,-1) def main(): n = int(input()) s = input() stack = [-1] cnt9 = 0 ans = 0 for i in range(n): if s[i] in '357': ans += 1 elif s[i] == '9': if stack[-1] == '1': ans += 1 stack.pop() else: cnt9 += 1 else: stack.append(s[i]) cnt1 = stack.count('1') while cnt1 >= 1 and cnt9 >= 2: cnt1 -= 1 cnt9 -= 2 ans += 1 ans += cnt1//2 print(ans) if __name__ =='__main__': main()