module Alphametic

  def self.solve(input)
    candidate = (input =~ /[\+=]X/ or input =~ /^X/) ? 1..9 : 0..9
    candidate.find {|i| eval(input.gsub('X', i.to_s).sub!('=', '==')) } || "NA"
  end
end

while line = $stdin.gets
  puts Alphametic.solve(line)
end