#include <iostream>
#include <string>

using namespace std;


bool flag;

#include <cstdlib>
#include <cctype>
class Form {
public:
  string str;
private:
  int pos;

public:
  int ans() {
    pos = 0;
    return exp();
  }
private:
  int exp() {
    int x = term();
    while(pos < str.length()) {
      if(str[pos] == '+') {
	++pos;
	x += factor();
      } else if(str[pos] == '-') {
	++pos;
	x -= factor();
      } else {
	break;
      }
    }
    return x;
  }
  int term() {
    int x = factor();
    while(pos < str.length()) {
      if(str[pos] == '*') {
	++pos;
	x *= factor();
      } else if(str[pos] == '/') {
	++pos;
	x /= factor();
      } else {
	break;
      }
    }
    return x;
  }
  int factor() {
    int x;
    if(str[pos] == '(') {
      ++pos; x = exp(); ++pos;
    } else {
      x = getNum();
    }
    return x;
  }
  int getNum() {
    int s = pos;
    int length = 0;
    while(isdigit(str[pos])) { ++pos; ++length; }
    string num = str.substr(s, length);
    if(num[0] == '0') flag = true;
    return atoi(num.c_str());
  }
};

string putX(string str, int x) {
  for(int i = 0; i < str.length(); ++i) {
    if(str[i] != 'X') continue;
    str[i] = '0' + x;
  }
  return str;
}

void solve(string &str) {
  Form form;
  string s1, s2;
  for(int i = 0;; ++i) {
    if(str[i] == '=') {
      s1 = str.substr(0, i);
      s2 = str.substr(i+1, str.size()-(i+1));
      break;
    }
  }

  for(int x = 0; x <= 9; ++x) {
    flag = false;
    form.str = putX(s1, x);
    if(form.ans() == atoi(putX(s2, x).c_str()) && !flag) {
      cout << x << endl;
      return;
    }
  }
  cout << "NA" << endl;
}

main() {
  string str;
  while(getline(cin, str)) solve(str);
}