#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;

Data getnum(){
  Data ret;
  while(pos<str.size() && str[pos]!='+' && str[pos]!='='){
    ret.x+='0';
    ret.i+='0';
    if(str[pos]=='X'){
      ret.x[ret.x.size()-1]='1';
    }else ret.i[ret.i.size()-1]=str[pos];
    ++pos;
  }
  ++pos;
  if(ret.x[ret.x.size()-1]=='1' && ret.x.size()>1)l0=1;
  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){
  string ret;
  reverse(ss.begin(),ss.end());

  int c=0;
  rep(i,ss.size()){
    int t=(ss[i]-'0')*r+c;
    c=t/10;
    t%=10;
    ret+=t+'0';
  }
  if(c)ret+=c+'0';
  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;
}

main(){
  while(cin>>str){
    pos=0;
    l0=0;
    l=getnum();
    m=getnum();
    r=getnum();

    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))break;
    }
    if(ans==10)cout<<"NA"<<endl;
    else cout<<ans<<endl;
  }
}