#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define INF (1<<29)

string str;
int pos;
int x;

int culc1();
int culc2();

int culc1() {
	int val = culc2();
	if (val == INF) return INF;
	
	while (str[pos] == '+' || str[pos] == '-') {
		char op = str[pos++];
		int val2 = culc2();
		if (val2 == INF) return INF;

		if (op == '+') val += val2;
		else val -= val2;
	}	
	return val;
}

int culc2() {
	int tmp = -1;
	
	if (str[pos] == 'X') {
		if (x == 0) return INF;
		str[pos] = x + '0';
		tmp = pos;
	}
	int num = str[pos++] - '0';
	
	if (tmp > -1) {
		str[tmp] = 'X';
		tmp = -1;
	}
	
	while (isdigit(str[pos]) || str[pos] == 'X') {
		if (str[pos] == 'X') {
			str[pos] = x + '0';
			tmp = pos;
		}
		num = num*10 + str[pos++] - '0';
		
		if (tmp > -1) {
			str[tmp] = 'X';
			tmp = -1;
		}
	}
	return num;
}

int main() {
	while (cin >> str) {
		pos = str.size();
		while (str[--pos] != '=');
		str[pos] = '-';
		
		int ans = -1;
		REP(i, 10) {
			x = i;
			pos = 0;
			int tmp = culc1();
			if (tmp == INF || tmp != 0) continue;
			ans = x; 
		}
		if (ans != -1) cout << ans << endl;
		else puts("NA");
	}
	return 0;
}