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() flag = False for i in range(len(li)): if flag == False: if li[i] == "1": flag = True tmp = i else: if li[i] == "9": flag = False idx.add(tmp) idx.add(i) ans += 1 li2 = [] for i in range(len(li)): if i not in idx: li2.append(li[i]) idx = set() flag = False for i in range(len(li2)): if flag == False: if li2[i] == "1": flag = True tmp = i else: if li2[i] == "1": flag = False idx.add(tmp) idx.add(i) ans += 1 li3 = [] f = 0 for i in range(len(li2)): if i not in idx: if li2[i] == "9": f += 1 else: if f >= 2: ans += 1 break else: break print(ans)