#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, char *> P;
const int L = 200;

P expr(char *p);

P fact(char *p){
  if(isdigit(*p)){
    int t = *(p++) - '0';
    while(isdigit(*p)) t = t * 10 + *(p++) - '0';
    return P(t, p);
  } else if(*p == '('){
    P r = expr(p + 1);
    if(*r.second != ')') exit(0); //閉じ括弧が無いエラー
    return P(r.first, r.second + 1);
  } else{
    exit(0); //括弧でも数字でもないエラー
  }
}

P term(char *p){
  P r = fact(p);
  while(*r.second == '*' || *r.second == '/'){
    char op = *r.second;
    int tmp = r.first;
    r = fact(r.second + 1);
    if(op == '*') r.first *= tmp;
    else r.first /= tmp;
  }
  return r;
}

P expr(char *p){
  P r = term(p);
  while(*r.second == '+' || *r.second == '-'){
    char op = *r.second;
    int tmp = r.first;
    r = term(r.second + 1);
    if(op == '+') r.first = tmp + r.first;
    else r.first = tmp - r.first;
  }
  return r;
}

int main() {
  string s;
  while(cin >>s){
    int ans = -1;
    REP(i, 10){
      char a[L], b[L];
      int al = 0, bl = 0, f = 0;
      REP(j, s.length()){
        if(s[j] == '=') f = 1;
        else if(f) b[bl++] = s[j];
        else a[al++] = s[j];
      }
      if(i == 0 && (a[0] == 'X' || b[0] == 'X')) continue;
      REP(j, al) if(a[j] == 'X') a[j] = i + '0';
      REP(j, bl) if(b[j] == 'X') b[j] = i + '0';
      a[al] = '\0'; b[bl] = '\0';
      P r = expr(a);
      if(r.first == atoi(b)) ans = i;
    }
    if(ans == -1) cout <<"NA" <<endl;
    else cout <<ans <<endl;
  }
  return 0;
}