#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;

string s;
string::iterator p;

int fact();
int term();
int exp();

int fact() {
  int x;
  string num;
  while(isdigit(*p)) {
    num += *p;
    ++p;
  }
  if(num.size()) {
    x = atoi(num.c_str());
  } else {
    ++p;
    x = exp();
    ++p;
  }
  return x;
}

int term() {
  int x = fact();
  while(*p == '*' || *p == '/') {
    if(*p == '*') {
      ++p;
      x *= fact();
    } else {
      ++p;
      x /= fact();
    }
  }
  return x;

}

int exp() {
  int x = term();
  while(*p == '+' || *p == '-') {
    if(*p == '+') {
      ++p;
      x += term();
    } else {
      ++p;
      x -= term();
    }
  }
  return x;
}

int main() {
  string t;
  while(cin >> t) {
    string a, b;
    int m = t.find('=');
    a = t.substr(0, m);
    b = t.substr(m+1);
    try {
      for(char x = '0'; x <= '9'; ++x) {
        string na = a;
        string nb = b;
        replace(na.begin(), na.end(), 'X', x);
        replace(nb.begin(), nb.end(), 'X', x);
        if(na[0] == '0' && na.size() >= 2) continue;
        if(nb[0] == '0' && nb.size() >= 2) continue;
        s = na + "$";
        p = s.begin();
        if(exp() == atoi(nb.c_str())) {
          cout << x << endl;
          throw 0;
        }
      }
      cout << "NA" << endl;
    } catch(...) {}
  }
  return 0;
}