$<.readlines.map(&:chomp).map {|l| l.split(/\+|=/)}.each do |given|
  catch(:jump) do
    10.times do |i|
      d = given.map {|a| a.gsub("X", i.to_s)}
      next unless d.select {|s| s.length >= 2 and s[0] == "0"}.empty?
      next unless d[0].to_i + d[1].to_i == d[2].to_i
      puts i
      throw(:jump)
    end
    puts "NA"
  end
end
