#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

typedef string::const_iterator state;
class parse_error {};

void cmpinc(state &it, char expected) {
	if (*it == expected) {
		it++;
	}
	else {
		cerr << "Expected '" << expected << "',";
		cerr << "got '" << *it << "'";

		cout << endl;
		throw parse_error();
	}
}

/*

EBNF

equation = integer "+" integer "=" integer;

*/

int X; //?????°??¨

int integer(state &it) {
	int ret = 0;
	while (true) {
		if (isdigit(*it)) {
			ret *= 10;
			ret += *it - '0';
			it++;
		}
		else if (*it == 'X') {
			ret *= 10;
			ret += X;
			it++;
		}
		else {
			break;
		}
	}
	return ret;
}

int main() {
	for (string s; getline(cin, s) && s != "$"; ) {
		s += "$";
		bool flag = false;

		for (X = 0; X < 10; X++) {
			state it = s.begin();

			int L, R, A;
			L = integer(it);
			cmpinc(it, '+');
			R = integer(it);
			cmpinc(it, '=');
			A = integer(it);

			//cerr << L << "+" << R << "=" << A << endl;

			if (L + R == A) {
				flag = true;
				break;
			}
		}

		if (flag)
			cout << X << endl;
		else
			cout << "NA" << endl;

	}
	return 0;
}