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 for i in range(min(len(one),len(nine))): if one[i] < nine[-1-i]: ans += 1 else: one = one[i:] nine = nine[:len(nine)-i] break for i in range(min(len(one),len(nine)//2)): if nine[2*i+1] > one[-1-i]: ans += 1 else: one = one[:len(one)-i] ans += len(one)//2 break print(ans)