Problem: 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

Solution (in CPP):

Solution:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
struct Int
{
	int a[130];
	Int(){memset(a,0,sizeof(a));}
};
Int add(Int p,Int q)
{
	Int ret;
	int k=0;
	for(int i=0;i<130;i++)
	{
		ret.a[i]=(k+p.a[i]+q.a[i])%10;
		k=(k+p.a[i]+q.a[i])/10;
	}
	return ret;
}
bool same(Int p,Int q)
{
	for(int i=0;i<130;i++)if(p.a[i]!=q.a[i])return false;
	return true;
}
void print(Int p)
{
	for(int i=0;i<130;i++)cout << p.a[i];
	cout << endl;
	return;
}
string s1,s2,s3;
bool check(int k)
{
	//cout << s1 << ' ' << s2 << ' ' << s3 << endl;
	if(k==0&&((s1[s1.size()-1]=='X'&&s1.size()>1)||(s2[s2.size()-1]=='X'&&s2.size()>1)||(s3[s3.size()-1]=='X'&&s3.size()>1)))return false;
	Int p,q,r,sum;
	//cout << "どどどどどーん" << endl;
	for(int i=0;i<130;i++)
	{
		//cout << s1[i];
		if(i<s1.size()&&s1[i]=='X')p.a[i]=k;
		else if(i<s1.size())p.a[i]=s1[i]-'0';
		if(i<s2.size()&&s2[i]=='X')q.a[i]=k;
		else if(i<s2.size())q.a[i]=s2[i]-'0';
		if(i<s3.size()&&s3[i]=='X')r.a[i]=k;
		else if(i<s3.size())r.a[i]=s3[i]-'0';
	}
	//cout << endl;
	//print(p);
	//print(q);
	sum=add(p,q);
	/*for(int i=0;i<130;i++)cout << p.a[i];
	cout << endl;
	for(int i=0;i<130;i++)cout << q.a[i];
	cout << endl;i*/
	//for(int i=0;i<130;i++)cout << sum.a[i];
	//cout << endl;
	//print(sum);
	//print(r);
	return same(sum,r);
}
int main()
{
	string s;
	while(cin >> s)
	{
		//cout << s[0]-'0' << endl;
		int len=s.size();
		s1.clear();s2.clear();s3.clear();
		int index=0;
		for(index=0;index<len;index++)
		{
			if(s[index]=='+')break;
			s1+=s[index];
		}
		index++;
		for(;index<len;index++)
		{
			if(s[index]=='=')break;
			s2+=s[index];
		}
		index++;
		for(;index<len;index++)s3+=s[index];
		reverse(s1.begin(),s1.end());
		reverse(s2.begin(),s2.end());
		reverse(s3.begin(),s3.end());
		//cout << s1 << ' ' << s2 << ' ' << s3 << endl;
		bool flag=false; 
		for(int i=0;i<10;i++)
		{
			if(check(i))
			{
				cout << i << endl;
				flag=true;
				break;
			}
		}
		if(!flag)cout << "NA" << endl;
		s.clear();
	}
	return 0;
}