/*
	AOJ_0110: Alphametic
*/
#include	<iostream>
#include	<string>
#include	<cstdlib>
#include	<vector>

using namespace std;

int Alp_calc(string);
int convert_Xtoi(string, int);

int main(void) {
	string str;
	int result;

	while (1) {
		cin >> str;
		if (cin.eof()) { break; }

		result = Alp_calc(str);
		if (result != -1) { cout << result << endl; }
		else { cout << "NA" << endl; }
	}
	return 0;
}

int Alp_calc(string str) {
	string sect_1, sect_2, solution;

	string::iterator it = str.begin();
	while (*it != '+') {
		sect_1 += *it;
		it++;
	} it++;
	while (*it != '=') {
		sect_2 += *it;
		it++;
	} it++;
	while (it != str.end()) {
		solution += *it;
		it++;
	}
	for (int i = 0; i < 10; i++) {
		int _i1 = convert_Xtoi(sect_1, i), _i2 = convert_Xtoi(sect_2, i), _il = convert_Xtoi(solution, i);
		if (_i1 + _i2 == _il) { return i; }
	}

	return -1;
}

int convert_Xtoi(string str, int n) {
	string::iterator it = str.begin();
	while (it != str.end()) {
		if (*it == 'X') { *it = n + '0'; }
		it++;
	}
	return atoi(str.c_str());
}