import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 def main(): n = int(input()) s = input() ans = 0 c1 = c9 = 0 for c in s: if c == "1": c1 += 1 elif c == "9": if c1 > 0: ans += 1 c1 -= 1 else: c9 += 1 else: ans += 1 c9 //= 2 ans += c9 ans += max(0, (c1 - c9)) // 2 print(ans) main()