N = gets.to_i S = gets.chomp.chars.map(&:to_i) ans = 0 counter = Hash.new(0) S.each do |s| if s != 1 && s != 9 ans += 1 elsif s == 1 counter[s] += 1 elsif s == 9 if counter[1] > 0 counter[1] -= 1 ans += 1 else counter[s] += 1 end end end if counter[9] >= 2 && counter[1] >= 1 a = counter[9] / 2 b = counter[1] c = [a, b].min ans += c counter[9] -= 2 * c counter[1] -= c end if counter[1] >= 2 ans += counter[1] / 2 end puts ans