#include <iostream>
#include <sstream>
#include <cstdio>

using namespace std;

int pos;
string expr;

int keisan();
int number();

int str_to_int(string str) {
	stringstream ss; int ret;

	ss << str;
	ss >> ret;

	return ret;
}

int keisan() {
	int left = number();

	while (expr[pos] != '=') {
		char c = expr[pos++];
		int right = number();

		if (c == '+') left += right;
		else left -= right;
	}

	return left;
}
int number() {
	string str = "";
	while (expr[pos] >= '0' && expr[pos] <= '9')
		str += expr[pos++];

	return str_to_int(str);
}

string replace(string str, char c1, char c2) {
	for (int i = 0; i < str.size(); ++i)
		if (str[i] == c1) str[i] = c2;

	return str;
}

int main() {
	char s[1000];
	while (scanf("%s", s) != EOF) {
		string str = "";
		for (int i = 0; s[i]; ++i) str += s[i];

		str = replace(str, '=', '-');
		str += '=';

		int ans = -1;
		for (int i = 0; i < 10; ++i) {
			pos = 0;
			expr = replace(str, 'X', i+'0');
			if (keisan() == 0) ans = i;
		}

		if (ans < 0) cout << "NA" << endl;
		else cout << ans << endl;
	}
}