N = int(input()) S = input() ans = 0 l = [] for i in S: if i == '1' or '9': l.append(i) else: ans += 1 one = 0 nine = 0 now = 0 count = 0 for i in l: if i == "1": now += 1 one += 1 else: nine += 1 if now > 0: count += 1 now -= 1 ans += count + (one - count) // 2 if one - count == 1 and nine - count >= 2: ans += 1 print(ans)