N = gets.to_i A = gets.split.map(&:to_i) m = A.sum % 10 nodes = [m] min_dist = Array.new(10, Float::INFINITY) min_dist[m] = 0 A.each do |a| m = a % 10 nodes.each do |n| next if min_dist[n] == Float::INFINITY nm = (n - m) % 10 dist = min_dist[n] + 1 next if min_dist[nm] <= dist min_dist[nm] = dist nodes << nm end end if min_dist[0] == Float::INFINITY puts 0 else puts N - min_dist[0] end