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 <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair
#define PB push_back

typedef struct{
  string x,i;
}Data;

string str;
Data l,m,r;
int pos;
int l0;
bool debug=0;

void printdata(Data);

Data getnum(){
  Data ret;
  while(pos<str.size() && (str[pos]=='X' || isdigit(str[pos]) ) ){
    if(str[pos]=='X'){
      ret.i+='0';
      ret.x+='1';
    }else{
      ret.i+=str[pos];
      ret.x+='0';
    }
    ++pos;
  }
  ++pos;
  if(ret.x[0]=='1' && ret.x.size()>1)l0=1;
  //printdata(ret);
  return ret;
}

string sadd(string l,string r){
  reverse(l.begin(),l.end());
  reverse(r.begin(),r.end());
  if(l.size()>r.size())swap(l,r);
  string ret;
  int c=0;
  int i;
  for(i=0;i<l.size();i++){
    int t=l[i]+r[i]+c-2*'0';
    c=t/10;
    t%=10;
    ret+=t+'0';
  }
  for(i;i<r.size();i++){
    int t=r[i]+c-'0';
    c=t/10;
    t%=10;
    ret+=t+'0';
  }
  if(c)ret+='1';
  reverse(ret.begin(),ret.end());
  return ret;
}

string mult(string ss,int r){
  reverse(ss.begin(),ss.end());
  string ret;
  int c=0;
  rep(i,ss.size()){
    int t=(ss[i]-'0')*r+c;
    c=t/10;
    t%=10;
    ret+='0'+t;
  }
  if(c)ret+='0'+c;
  reverse(ret.begin(),ret.end());
  return ret;
}

bool compare(string l,string r){
  bool ret=true;
  if(l.size()>r.size())swap(l,r);

  reverse(l.begin(),l.end());
  reverse(r.begin(),r.end());

  for(int i=0;i<l.size();i++){
    if(l[i]!=r[i])ret=false;
  }
  for(int i=l.size();i<r.size();i++){
    if(r[i]!='0')ret=false;
  }
  return ret;
}

void printdata(Data in){
  cout<<in.x<<" "<<in.i<<endl;
}

int main(){
  while(getline(cin,str)){
    if(debug)cout<<str<<endl;
    pos=0;
    l0=0;
    l=getnum();
    m=getnum();
    r=getnum();
    if(debug){
      printdata(l);
      printdata(m);
      printdata(r);
    }

    Data lm;
    lm.i=sadd(l.i,m.i);
    lm.x=sadd(l.x,m.x);
    int ans=0;
    for(ans=l0;ans<10;ans++){
      Data tlm,tr;
      tlm.x=mult(lm.x,ans);
      tlm.i=lm.i;
      tr.x=mult(r.x,ans);
      tr.i=r.i;
      
      string ssl=sadd(tlm.x,tlm.i),ssr=sadd(tr.x,tr.i);
      if(compare(ssl,ssr)){
        if(debug)cout<<ssl<<" "<<ssr<<endl;
        break;
      }
    }
    if(ans==10)cout<<"NA"<<endl;
    else cout<<ans<<endl;
  }
}