The problem of hiding a part of a formula and searching for the hidden number is called verbal arithmetic. This time, I'm dealing with an expression in which some numbers in the expression are hidden by X. Enter the following formula and create a program that outputs the result.

Formula

* A simple one-line addition expression in the form of "number string + number string = number string".
* A "number sequence" is a sequence of numbers 0-9 and the letter X.
* It is assumed that the leftmost number in the "number string" with two or more digits is not 0.
* X must be at least one in the entire formula.



result

* The answer to the verbal arithmetic. It is one of 0 to 9 with a value of X such that the formula holds. Suppose there are no more than one answer.
* If there is no answer, the result should be “NA”.



Input

Given multiple datasets. For each dataset, an addition expression containing one or more Xs (a string of up to 126 characters without spaces) is given on one line. The number of datasets does not exceed 150.

Output

For each data set, output the result of the verbal arithmetic on one line. Print the numbers 0-9 or NA.

Example

Input

123+4X6=X79
12X+4X6=X79
XX22+89=X2XX


Output

5
NA
1

Source: aizu | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
import sys, re
for e in sys.stdin:
	s = any([len(x) > 1 and x[0] == 'X' for x in re.split('[+=]', e.strip())])
	for i in '0123456789'[s:]:
		if eval(e.replace('X', i).replace('=', '==')):
			print(i)
			break
	else:
		print('NA')


import re, sys

def chk(t):
	for i in range(10):
		e = re.split('[+=]', re.sub('X', str(i), t))
		if e[0][0] == '0' and len(e[0]) > 1 or (e[1][0] == '0' and len(e[1]) > 1) or (e[2][0] == '0' and len(e[2]) > 1):
			continue
		if eval(e[0] + '+' + e[1]) == eval(e[2]):
			return i
	return 10
l = [chk(i.strip()) for i in sys.stdin]
[print(i) if i != 10 else print('NA') for i in l]


import sys
import re
for line in sys.stdin:
	line = line.replace('\n', '')
	s = re.split('[+=]', line)
	line = line.replace('=', '==')
	ans = 'NA'
	f = any([x != 'X' and x[0] == 'X' for x in s])
	for i in '0123456789'[f:]:
		if eval(line.replace('X', i)):
			ans = i
			break
	print(ans)


def get_input():
	while True:
		try:
			yield ''.join(input())
		except EOFError:
			break
N = list(get_input())
for l in range(len(N)):
	(s1, t) = N[l].split('+')
	(s2, s3) = t.split('=')
	ans = -1
	if len(s1) > 1 and s1[0] == 'X' or (len(s2) > 1 and s2[0] == 'X') or (len(s3) > 1 and s3[0] == 'X'):
		for i in range(1, 10):
			n1 = int(s1.replace('X', str(i)))
			n2 = int(s2.replace('X', str(i)))
			n3 = int(s3.replace('X', str(i)))
			if n1 + n2 == n3:
				ans = i
				break
	else:
		for i in range(10):
			n1 = int(s1.replace('X', str(i)))
			n2 = int(s2.replace('X', str(i)))
			n3 = int(s3.replace('X', str(i)))
			if n1 + n2 == n3:
				ans = i
				break
	if ans >= 0:
		print(ans)
	else:
		print('NA')


for line in open(0).readlines():
	s = line.strip()
	(a, s) = s.split('+')
	(b, c) = s.split('=')
	f = lambda x: len(x) > 1 and x[0] == 'X'
	g = lambda s, x: int(s.replace('X', str(x)))
	for x in range(f(a) or f(b) or f(c), 10):
		if g(a, x) + g(b, x) == g(c, x):
			print(x)
			break
	else:
		print('NA')


def restore(sec, x):
	return int(sec.replace('X', str(x)))
while True:
	try:
		s = input()
		p_ind = s.index('+')
		e_ind = s.index('=')
		sec1 = s[:p_ind]
		sec2 = s[p_ind + 1:e_ind]
		sec3 = s[e_ind + 1:]
		for x in range(10):
			if not (not x and (sec1[0] == 'X' and len(sec1) > 1 or (sec2[0] == 'X' and len(sec2) > 1) or (sec3[0] == 'X' and len(sec3) > 1))):
				if restore(sec1, x) + restore(sec2, x) == restore(sec3, x):
					print(x)
					break
		else:
			print('NA')
	except EOFError:
		break


while 1:
	try:
		(ab, c) = list(input().split('='))
	except EOFError:
		break
	(a, b) = list(ab.split('+'))
	start = 0
	if a[0] == 'X' and len(a) > 1 or (b[0] == 'X' and len(b) > 1) or (c[0] == 'X' and len(c) > 1):
		start = 1
	for i in range(start, 10):
		na = a.replace('X', str(i))
		nb = b.replace('X', str(i))
		nc = c.replace('X', str(i))
		if int(na) + int(nb) == int(nc):
			print(i)
			break
	else:
		print('NA')


import sys
for s in sys.stdin:
	s = s[:-1]
	p = s.split('=')
	ans = 'NA'
	st = 0
	tmp = p[0].split('+')
	if tmp[0][0] == 'X' and len(tmp[0]) > 1:
		st = 1
	if tmp[1][0] == 'X' and len(tmp[1]) > 1:
		st = 1
	if p[1][0] == 'X' and len(p[1]) > 1:
		st = 1
	for i in range(st, 10):
		a = eval(p[0].replace('X', str(i)))
		b = eval(p[1].replace('X', str(i)))
		if a == b:
			ans = i
			break
	print(ans)


while True:
	try:
		(a, z) = input().split('=')
		(x, y) = a.split('+')
		start = 0
		if len(x) > 1 and x[0] == 'X' or (len(y) > 1 and y[0] == 'X') or (len(z) > 1 and z[0] == 'X'):
			start = 1
		ans = False
		for i in range(start, 10):
			x1 = x.replace('X', str(i))
			y1 = y.replace('X', str(i))
			z1 = z.replace('X', str(i))
			if int(x1) + int(y1) == int(z1):
				print(i)
				ans = True
				break
		if ans == False:
			print('NA')
	except EOFError:
		break


while 1:
	try:
		(ab, s) = list(input().split('='))
		(a, b) = list(ab.split('+'))
		start = 0
		if len(a) > 1 and a[0] == 'X' or (len(b) > 1 and b[0] == 'X') or (len(s) > 1 and s[0] == 'X'):
			start = 1
		f = 1
		for x in range(start, 10):
			na = a.replace('X', str(x))
			nb = b.replace('X', str(x))
			ns = s.replace('X', str(x))
			if int(na) + int(nb) == int(ns):
				print(x)
				f = 0
				break
		if f:
			print('NA')
	except:
		break


import sys
while True:
	try:
		s = input()
		ans = s.split('=')[1]
		(a, b) = s.split('=')[0].split('+')
		for X in range(10):
			_a = a.replace('X', str(X))
			if str(int(_a)) != _a:
				continue
			_b = b.replace('X', str(X))
			if str(int(_b)) != _b:
				continue
			_ans = ans.replace('X', str(X))
			if str(int(_ans)) != _ans:
				continue
			if int(_a) + int(_b) == int(_ans):
				print(X)
				break
		else:
			print('NA')
	except EOFError:
		sys.exit(0)


import sys
t = 'X'
for e in sys.stdin:
	for i in '0123456789'[(e[0] == t) * (e[1] != '+') or ('+X' in e) * ('+X=' not in e):]:
		(l, r) = e.replace(t, i).split('=')
		if sum(map(int, l.split('+'))) == int(r):
			print(i)
			break
	else:
		print('NA')


while True:
	try:
		dataset = input()
	except:
		break
	flag = True
	for i in range(10):
		sequence = dataset.replace('=', '+').split('+')
		if i == 0 and any([True if seq[0] == 'X' and len(seq) >= 2 else False for seq in sequence]):
			continue
		(a, b, c) = map(int, [seq.replace('X', str(i)) for seq in sequence])
		if a + b == c:
			print(i)
			flag = False
			break
	if flag:
		print('NA')


while True:
	try:
		st0 = input().strip('\n').replace('+', ',').replace('=', ',')
		for j in range(10):
			i = 9 - j
			(a, b, c) = st0.replace('X', str(i)).split(',')
			if i == 0:
				if a[0] == '0' and len(a) > 1:
					continue
				if b[0] == '0' and len(b) > 1:
					continue
				if c[0] == '0' and len(c) > 1:
					continue
			if int(a) + int(b) == int(c):
				print(i)
				break
		else:
			print('NA')
	except:
		break


import sys
import re

def solve(exp):
	p1 = re.compile('^0+')
	for i in range(10):
		modified_exp = exp.replace('X', str(i))
		(left, right) = modified_exp.split('=')
		(left1, left2) = left.split('+')
		left1 = p1.sub('', left1)
		if left1 == '':
			left1 = '0'
		left2 = p1.sub('', left2)
		if left2 == '':
			left2 = '0'
		right = p1.sub('', right)
		if right == '':
			right = '0'
		if int(left1) + int(left2) == int(right):
			return i
	return 'NA'

def solve2(exp):
	for i in range(10):
		(left, right) = exp.split('=')
		(left1, left2) = left.split('+')
		left1 = left1.replace('X', str(i))
		left2 = left2.replace('X', str(i))
		right = right.replace('X', str(i))
		if len(left1) > 1 and left1[0] == '0':
			continue
		if len(left2) > 1 and left2[0] == '0':
			continue
		if len(right) > 1 and right[0] == '0':
			continue
		if int(left1, base=10) + int(left2, base=10) == int(right, base=10):
			return i
	return 'NA'

def main(args):
	for line in sys.stdin:
		result = solve2(line.strip())
		print(result)
main(sys.argv[1:])


import sys
(p, t, q) = '+X='
for e in sys.stdin:
	for i in '0123456789'[(e[0] == t) * (e[1] != p) or (p + t in e) * ('+X=' not in e):]:
		(l, r) = e.replace(t, i).split(q)
		if sum(map(int, l.split(p))) == int(r):
			print(i)
			break
	else:
		print('NA')


import re
while True:
	try:
		Q = re.split('[+=]', input())
		A = Q[0]
		B = Q[1]
		S = Q[2]
		start = 0
		ans = 'NA'
		if A[0] == 'X' and len(A) > 1 or (B[0] == 'X' and len(B) > 1) or (S[0] == 'X' and len(S) > 1):
			start = 1
		for i in range(start, 10):
			a = A.replace('X', str(i))
			b = B.replace('X', str(i))
			s = S.replace('X', str(i))
			if int(a) + int(b) == int(s):
				ans = i
				break
			else:
				pass
		print(ans)
	except:
		break


import re, sys
t = 'X'
for e in sys.stdin:
	for i in '0123456789'[any([len(x) > 1 and x[0] == 'X' for x in re.split('[+=]', e.strip())]):]:
		(l, r) = e.replace(t, i).split('=')
		if sum(map(int, l.split('+'))) == int(r):
			print(i)
			break
	else:
		print('NA')


import copy
while 1:
	try:
		s = input().split('=')
		t = s[0].split('+')
		t.append(s[1])
		copy_t = copy.copy(t)
		flag = 0
		check = 0
		for i in range(3):
			if t[i][0] == 'X' and len(t[i]) >= 2:
				check = 1
		for i in range(10):
			if check == 1 and i == 0:
				continue
			for j in range(3):
				t[j] = t[j].replace('X', str(i))
			if int(t[0]) + int(t[1]) == int(t[2]):
				flag = 1
				print(i)
				break
			t = copy.copy(copy_t)
		if flag == 0:
			print('NA')
	except:
		break


import sys
for e in sys.stdin:
	for i in '0123456789'[(e[0] == 'X') * (e[1] != '+') or ('+X' in e) * ('+X=' not in e):]:
		(l, r) = e.replace('X', i).split('=')
		if eval(l) == int(r):
			print(i)
			break
	else:
		print('NA')


import sys
(p, t) = '+X'
for e in sys.stdin:
	for i in '0123456789'[(e[0] == t) * (e[1] != p) or (p + t in e) * ('+X=' not in e):]:
		(l, r) = e.replace(t, i).split('=')
		if sum(map(int, l.split(p))) == int(r):
			print(i)
			break
	else:
		print('NA')


import sys
t = 'X'
for e in sys.stdin:
	for i in '0123456789'[(e[0] == t) * (e[1] != '+') or ('+X' in e) * ('+X=' not in e) or ('=X' in e) * (e[-1] == t):]:
		(l, r) = e.replace(t, i).split('=')
		if sum(map(int, l.split('+'))) == int(r):
			print(i)
			break
	else:
		print('NA')


while 1:
	try:
		(l, r) = map(str, input().split('='))
		(l, l2) = map(str, l.split('+'))
		count = 0
		n = 0
		if len(l) > 1 and l[0] == 'X' or (len(l2) > 1 and l2[0] == 'X') or (len(r) > 1 and r[0] == 'X'):
			n = 1
		for i in range(n, 10):
			lx = l.replace('X', str(i))
			l2x = l2.replace('X', str(i))
			rx = r.replace('X', str(i))
			if int(lx) + int(l2x) == int(rx):
				print(i)
				count += 1
				break
		if count == 0:
			print('NA')
	except:
		break


import copy
try:
	while True:
		A = [[]]
		L = input()
		i = 0
		flag = 0
		for a in L:
			if a != '+' and a != '=':
				A[i].append(a)
			else:
				i = i + 1
				A.append([])
		for a in A:
			if 'X' == a[0] and len(a) != 1:
				flag = 1
		for i in range(10):
			B = copy.deepcopy(A)
			for (Bi, b) in enumerate(B):
				for (bi, k) in enumerate(b):
					if k == 'X':
						B[Bi][bi] = str(i)
				B[Bi] = int(''.join(B[Bi]))
			if B[0] + B[1] == B[2]:
				if i == 0 and flag == 1:
					print('NA')
					flag = 2
				else:
					print(i)
					flag = 2
		if flag == 1 or flag == 0:
			print('NA')
except EOFError:
	pass


import sys
(p, t) = ('+X=', 'X')
for e in sys.stdin:
	for i in '0123456789'[(e[0] == t) * (e[1] != '+') or (p[:2] in e) * (p not in e):]:
		(l, r) = e.replace(t, i).split('=')
		if sum(map(int, l.split('+'))) == int(r):
			print(i)
			break
	else:
		print('NA')


import sys
t = 'X'
for e in sys.stdin:
	for i in '0123456789'[(e[0] == t) * ('+' != e[1]) or ('+X' in e) * ('+X=' not in e) or ('=X' in e) * (e[-1] == t):]:
		(l, r) = e.replace(t, i).split('=')
		if sum(map(int, l.split('+'))) == int(r):
			print(i)
			break
	else:
		print('NA')


while True:
	try:
		st0 = input()
		st0 = st0.strip('\n').replace('+', ',').replace('=', ',')
		for i in range(10):
			(a, b, c) = st0.replace('X', str(i)).split(',')
			if a[0] == '0' and len(a) > 1:
				continue
			if b[0] == '0' and len(b) > 1:
				continue
			if c[0] == '0' and len(c) > 1:
				continue
			if int(a) + int(b) == int(c):
				print(i)
				break
		else:
			print('NA')
	except:
		break


import re, sys
for e in sys.stdin:
	s = any([len(x) > 1 and x[0] == 'X' for x in re.split('[+=]', e.strip())])
	for i in '0123456789'[s:]:
		if eval(e.replace('X', i).replace('=', '==')):
			print(i)
			break
	else:
		print('NA')


import sys
t = 'X'
for e in sys.stdin:
	for i in '0123456789'[e[0] == t and '+' != e[1] or ('+X=' not in e and '+X' in e) or (e[-1] == t and '=X' in e):]:
		(l, r) = e.replace(t, i).split('=')
		if sum(map(int, l.split('+'))) == int(r):
			print(i)
			break
	else:
		print('NA')


import re
while True:
	try:
		s = input().strip()
	except:
		break
	var = list(re.split('[+=]', s))
	ans = -1
	for i in range(10):
		num = []
		ok = True
		for v in var:
			if i == 0 and len(v) >= 2 and (v[0] == 'X'):
				ok = False
				break
			x = 0
			for j in range(len(v)):
				if v[j] == 'X':
					x = x * 10 + i
				else:
					x = x * 10 + ord(v[j]) - ord('0')
			num.append(x)
		if ok:
			if num[0] + num[1] == num[2]:
				ans = i
				break
	if ans >= 0:
		print(ans)
	else:
		print('NA')


import re
import sys
s = sys.stdin.readline()
while s:
	for i in range(10):
		tmp = s.replace('X', str(i))
		(a, b, c) = map(int, re.split('[+=]', tmp))
		if a + b - c == 0:
			if len(str(a) + str(b) + str(c)) + 2 == len(tmp.rstrip()):
				print(i)
				break
			else:
				continue
	else:
		print('NA')
	s = sys.stdin.readline()


import sys
t = 'X'
for e in sys.stdin:
	for i in '0123456789'[(e[0] == t) * (e[1] != '+') or ('+X' in e) * ('+X=' not in e):]:
		(l, r) = e.replace(t, i).split('=')
		if eval(l) == int(r):
			print(i)
			break
	else:
		print('NA')


while True:
	try:
		s = input()
	except:
		break
	(t, sc) = s.split('=')
	(sa, sb) = t.split('+')
	if len(sa) > 1 and sa[0] == 'X' or (len(sb) > 1 and sb[0] == 'X') or (len(sc) > 1 and sc[0] == 'X'):
		start = 1
	else:
		start = 0
	f = 0
	for i in range(start, 10):
		na = int(sa.replace('X', str(i)))
		nb = int(sb.replace('X', str(i)))
		nc = int(sc.replace('X', str(i)))
		if na + nb == nc:
			f += 1
			break
	if f > 0:
		print(i)
	else:
		print('NA')


import re
while 1:
	try:
		f = input()
	except:
		break
	s = any([len(x) > 1 and x[0] == 'X' for x in re.split('[+=]', f)])
	f = f.replace('=', '==')
	for i in '0123456789'[s:]:
		if eval(f.replace('X', i)):
			print(i)
			break
	else:
		print('NA')


import sys, re
for e in sys.stdin:
	for i in '0123456789'[any([len(x) > 1 and x[0] == 'X' for x in re.split('[+=]', e.strip())]):]:
		(l, r) = e.replace('X', i).split('=')
		if sum(map(int, l.split('+'))) == int(r):
			print(i)
			break
	else:
		print('NA')


def cheak(x):
	if x[0] == '0' and len(x) > 1:
		return True
	return False

def find(ss):
	for i in range(0, 10):
		s = ss.replace('X', str(i))
		(ab, c) = list(s.split('=='))
		(a, b) = list(ab.split('+'))
		if i == 0 and (cheak(a) or cheak(b) or cheak(c)):
			continue
		if eval(s):
			print(i)
			return
	print('NA')
while True:
	try:
		s = input().replace('=', '==')
		find(s)
	except:
		break


import sys
import re

def line():
	return sys.stdin.readline().strip()
while True:
	try:
		e = re.findall('[0-9X]+', line())
		ans = -1
		for i in range(10):
			(a, b, c) = [_.replace('X', str(i)) for _ in e]
			if i == 0 and (a[0] == '0' and len(a) != 1 or (b[0] == '0' and len(b) != 1) or (c[0] == '0' and len(c) != 1)):
				continue
			if int(a) + int(b) == int(c):
				ans = i
				break
		if ans == -1:
			print('NA')
		else:
			print(ans)
	except:
		break


import re
while 1:
	try:
		N = input()
	except:
		break
	NUMBER = any([len(x) > 1 and x[0] == 'X' for x in re.split('[+=]', N)])
	N = N.replace('=', '==')
	for i in '0123456789'[NUMBER:]:
		if eval(N.replace('X', i)):
			print(i)
			break
	else:
		print('NA')


inputs = []
while True:
	try:
		inputs.append(input())
	except EOFError:
		break
for i in inputs:
	(a, c) = i.split('=')
	(a, b) = a.split('+')
	for x in range(0, 10):
		if x == 0:
			if a[0] == 'X' and len(a) > 1 or (b[0] == 'X' and len(b) > 1) or (c[0] == 'X' and len(c) > 1):
				continue
		A = a.replace('X', str(x))
		B = b.replace('X', str(x))
		C = c.replace('X', str(x))
		if int(A) + int(B) == int(C):
			print(x)
			break
		if x == 9:
			print('NA')


import re
while True:
	try:
		line = input()
	except:
		break
	arr = re.findall('[0-9X]+', line)
	ans = -1
	for i in '0123456789':
		(a, b, r) = [s.replace('X', str(i)) for s in arr]
		if i == '0' and (a[0] == '0' and len(a) > 1) or (b[0] == '0' and len(b) > 1) or (r[0] == '0' and len(r) > 1):
			continue
		if int(a) + int(b) == int(r):
			ans = i
			break
	if ans == -1:
		print('NA')
	else:
		print(ans)


import sys
import os
import math
import re
for s in sys.stdin:
	equation = s.strip()
	equation = equation.replace('=', '==')
	found = False
	for i in range(10):
		candidate = equation.replace('X', str(i))
		a = candidate.split('+')[0]
		b_c = candidate.split('+')[1]
		b = b_c.split('==')[0]
		c = b_c.split('==')[1]
		if a[0] == '0' and len(a) != 1 or (b[0] == '0' and len(b) != 1) or (c[0] == '0' and len(c) != 1):
			pass
		elif eval(candidate):
			print(i)
			found = True
	if not found:
		print('NA')


import sys
t = 'X'
for e in sys.stdin:
	for i in '0123456789'[(e[0] == t) * (e[1] != '+') or ('+X' in e) * ('+X=' not in e) or (e[-1] == t and '=X' in e):]:
		(l, r) = e.replace(t, i).split('=')
		if sum(map(int, l.split('+'))) == int(r):
			print(i)
			break
	else:
		print('NA')


while True:
	try:
		s = 0
		inp = input().split('=')
		f = inp[0].split('+')
		if len(f[0]) > 1 and f[0][0] == 'X' or (len(f[1]) > 1 and f[1][0] == 'X') or (len(inp[1]) > 1 and inp[1][0] == 'X'):
			s = 1
		for i in range(s, 10):
			left = eval(inp[0].replace('X', str(i)))
			right = int(inp[1].replace('X', str(i)))
			if left == right:
				print(i)
				break
		else:
			print('NA')
	except:
		break


while True:
	try:
		(a, c) = input().split('=')
		(a, b) = a.split('+')
		for i in range(10):
			if i == 0 and (len(a) > 1 and a[0] == 'X' or (len(b) > 1 and b[0] == 'X') or (len(c) > 1 and c[0] == 'X')):
				continue
			if int(a.replace('X', str(i))) + int(b.replace('X', str(i))) == int(c.replace('X', str(i))):
				print(i)
				break
		else:
			print('NA')
	except:
		break


import sys
(p, t) = '+X'
for e in sys.stdin:
	for i in '0123456789'[(e[0] == t) * (e[1] != p) or ('+X' in e) * ('+X=' not in e):]:
		(l, r) = e.replace(t, i).split('=')
		if sum(map(int, l.split(p))) == int(r):
			print(i)
			break
	else:
		print('NA')


import re
while True:
	try:
		s = input()
	except EOFError:
		break
	for x in '0123456789':
		t = s.replace('X', x)
		(a, b, c) = re.split('[+=]', t)
		if len(a) > 1 and a[0] == '0':
			continue
		if len(b) > 1 and b[0] == '0':
			continue
		if len(c) > 1 and c[0] == '0':
			continue
		(a, b, c) = map(int, (a, b, c))
		if a + b != c:
			continue
		print(x)
		break
	else:
		print('NA')


while True:
	try:
		l = input().rstrip()
		[a, b] = l.split('+')
		[c, d] = b.split('=')
		for i in range(10):
			if i == 0:
				if a[0] == 'X' != a or c[0] == 'X' != c or d[0] == 'X' != d:
					pass
				else:
					A = int(a.replace('X', str(i)))
					C = int(c.replace('X', str(i)))
					D = int(d.replace('X', str(i)))
					if A + C == D:
						print(i)
						break
			else:
				A = int(a.replace('X', str(i)))
				C = int(c.replace('X', str(i)))
				D = int(d.replace('X', str(i)))
				if A + C == D:
					print(i)
					break
		else:
			print('NA')
	except:
		break


while 1:
	try:
		(ab, s) = list(input().split('='))
		(a, b) = list(ab.split('+'))
		start = 0
		if len(a) > 1 and a[0] == 'X' or (len(b) > 1 and b[0] == 'X') or (len(s) > 1 and s[0] == 'X'):
			start = 1
		flg = 1
		for x in range(start, 10):
			new_a = a.replace('X', str(x))
			new_b = b.replace('X', str(x))
			new_s = s.replace('X', str(x))
			if int(new_a) + int(new_b) == int(new_s):
				flg = 0
				print(x)
				break
		if flg:
			print('NA')
	except:
		break


import sys
t = 'X'
for e in sys.stdin:
	for i in '0123456789'[(e[0] == t) * (e[1] != '+') or ('+X' in e) * ('+X=' not in e) or e[-2:] == '=X':]:
		(l, r) = e.replace(t, i).split('=')
		if sum(map(int, l.split('+'))) == int(r):
			print(i)
			break
	else:
		print('NA')