#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
  string s;
  int a[222],p,q;
  while(cin >> s){
    bool f = true;
    for(int k = 0;k < 10; k++){
      p = a[0] = 0;
      for(int i = 0; i < (int)s.size(); i++){
	if('0' <= s[i] && s[i] <= '9'){
	  a[p] *= 10;
	  a[p] += s[i] - '0';
	}else if(s[i] == 'X'){
	  a[p] *= 10;
	  a[p] += k;
	}else{
	  p++;
	  if(s[i] == '=') q=p;
	  a[p] = 0;
	}
      }
      int b = 0,c = 0;
      for(int i = 0; i < q; i++) b += a[i];
      for(int i = q; i <= p; i++) c += a[i];
      if(b == c){
	cout << k << endl;
	f = false;
	break;
      }
    }
    if(f) cout << "NA" << endl;
  }
}