n = int(input()) S = input() one = [] nine = [] ans = 0 for i,s in enumerate(S): if s == "1": one.append(i) elif s == "9": nine.append(i) else: ans += 1 add = 0 for i in range(min(len(one),len(nine))): if one[i] < nine[-1]: ans += 1 add += 1 nine.pop() else: break one = one[add:] for i in range(min(len(one),len(nine)//2)): if nine[2*i+1] < one[-1]: ans += 1 one.pop() else: break ans += len(one)//2 print(ans)