N = int(input()) S = input() one = 0 ans = 0 for s in S: if s == "1": if one: ans += 1 one -= 1 else: one += 1 elif s == "9": if one: ans += 1 one -= 1 else: ans += 1 print(ans)