local n = io.read("*n", "*l") local s = io.read() local ret = 0 local cur9 = 0 local cur1 = 0 for i = 1, n do local ss = s:sub(i, i):byte() - 48 if ss == 1 then if 2 <= cur9 then -- 991 cur9 = cur9 - 2 ret = ret + 1 elseif 1 <= cur1 then -- 11 cur1 = cur1 - 1 ret = ret + 1 else cur1 = cur1 + 1 end elseif ss == 9 then if 1 <= cur1 then -- 19 cur1 = cur1 - 1 ret = ret + 1 else cur9 = cur9 + 1 end else ret = ret + 1 end end print(ret)