from collections import deque n = int(input()) s = input() li = [] ans = 0 for i in range(n): if s[i] != "1" and s[i] != "9": ans += 1 else: li.append(s[i]) idx = set() d1 = deque() #d9 = deque() for i in range(len(li)): if li[i] == "1": d1.append(i) if li[i] == "9": if len(d1) > 0: tmp = d1.popleft() idx.add(tmp) idx.add(i) ans += 1 li2 = [] for i in range(len(li)): if i not in idx: li2.append(li[i]) #print(li2,ans,len(li2)) #exit() n9 = 0 n1 = 0 for i in range(len(li2)): if li2[i] == "1": n9 = i n1 = len(li2)-i break tmp = min(n9//2,n1) ans += tmp ans += (n1-tmp)//2 print(ans)