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<iostream>
#include<sstream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cfloat>
#include<functional>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<bitset>
#include<list>
#include<numeric>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << x << "\n"
#define pri2(x, y) cout << x << " " << y << "\n"
#define pri3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << x << "\n"
#define debug2(x, y) cout << " --- " << x << " " << y << "\n"
#define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)
#define N 150


signed main(void){
  int i, j, k;
  for(int testcase = 0;testcase < 1234567;testcase++){
    string s;
    for(;getline(cin, s);){
      bool fl = true;
      int lh[N] = {0}, rh[N] = {0};
      int lhx[N] = {0}, rhx[N] = {0};
      for(i = s.size() - 1;;--i){
        if(s[i] == '=')break;
        else if(s[i] == 'X')rhx[s.size() - 1 - i]++;
        else rh[s.size() - 1 - i] += (int)(s[i] - '0');
      }
      if(s[i + 1] == 'X' && i + 2 != s.size())fl = false;
      --i;
      for(j = i;;--j){
        if(s[j] == '+')break;
        else if(s[j] == 'X')lhx[i - j]++;
        else lh[i - j] += (int)(s[j] - '0');
      }
      if(s[j + 1] == 'X' && s[j + 2] != '=')fl = false;
      i = j - 1;
      for(j = i;j >= 0;--j){
        if(s[j] == 'X')lhx[i - j]++;
        else lh[i - j] += (int)(s[j] - '0');
      }
      if(s[0] == 'X' && s[1] != '+')fl = false;
/*
      rep(i, 10){
        debug(i);
        printf("%d + %dx == %d + %dx\n", lh[i], lhx[i], rh[i], rhx[i]);
      }*/

      rep(k, 10){
        if(k == 0 && !fl)continue;
        int l = 0, r = 0;
        rep(i, N){
          if((lh[i] + lhx[i] * k + l) % 10 != (rh[i] + rhx[i] * k + r) % 10)break;
          l = (lh[i] + lhx[i] * k + l) / 10;
          r = (rh[i] + rhx[i] * k + r) / 10;
        }
        if(i == N){
          pri(k); break;
        }
      }
      if(k == 10)pri("NA");
      s.clear();
    }

/*/

//*/ break;
  }
  return 0;
}