def erase_first_zero_then_eval(lo, ro, ans)
	return false if ((lo.size >= 2) and lo[0] == "0") or ((ro.size >= 2) and ro[0] == "0")
	if lo.to_i + ro.to_i == ans.to_i
		return true
	else
		return false
	end
end

def has_answer?(formula)
	(0..9).to_a.each do |x|
		lo, ro, ans = formula.gsub("X", x.to_s).scan(/\d+/)
		return x if erase_first_zero_then_eval(lo, ro, ans)
	end
	false
end

readlines.each do |f|
	ans = has_answer?(f)
	if ans
		puts ans
	else
		puts "NA"
	end
end