def erase_first_zero_then_eval(lo, ro, ans)
	[lo,ro,ans].each { |x| x.delete!(x[0]) while x[0]=="0" }
	eval(lo+"+"+ro+"=="+ans)
end
readlines.each do |l|
	xn = l.count("X")
	formula = l.dup
	(0..9).to_a.each do |x|
		lo, ro, ans = formula.gsub("X", x.to_s).gsub(/\d+/).map{ |this| this }
		if erase_first_zero_then_eval(lo, ro, ans)
			puts x
			break
		end
		puts "NA" if x == 9
	end
end