while l = gets
  res = nil
  right, left = l.split('=')
  ('0'..'9').to_a.each do |i|
    eval right.gsub(/X/, i)
    if (eval right.gsub(/X/, i)) == left.gsub(/X/, i).to_i
      res = i
      break
    end
  end
  puts (res.nil?) ? 'NA' : res
end