#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(void) {
	string str;
	
	while(cin >> str) {
		int ans = -1;
		for(int i = 0; i < 10; i++) {
			string cp(str.begin(), str.end());
			vector<string> a;
			bool flag = true;
			string sum_str = "";

			for(int j = 0; j != string::npos;) {
				j = cp.find('X', j);
				if(j != string::npos)
					cp[j] = i + '0';
			}

			for(int j = 0, k = 0; j < cp.size(); k++, j++) {
				int start = j;
				string tmp;
				while(j < cp.size() && '0' <= cp[j] && cp[j] <= '9') j++;
				tmp = string(cp.begin() + start, cp.begin() + j);
				a.push_back(tmp);
			}

			if((a[0][0] == '0' && a[0].size() > 1) || (a[1][0] == '0' && a[1].size() > 1) || (a[2][0] == '0' && a[2].size() > 1))
				flag = false;

			for(int j = 0, carryout = 0; j < a[0].size() || j < a[1].size() || carryout; j++) {
				int tmp = carryout;
				if(j < a[0].size() && j >= a[1].size())
					tmp += a[0][a[0].size() - 1 - j] - '0';
				else if(j >= a[0].size() && j < a[1].size())
					tmp += a[1][a[1].size() - 1 - j] - '0';
				else if(j < a[0].size() && j < a[1].size())
					tmp += + a[0][a[0].size() - 1 - j] + a[1][a[1].size() - 1 - j] - '0' * 2;

				sum_str += tmp % 10 + '0';
				carryout = tmp / 10;
			}
			reverse(sum_str.begin(), sum_str.end());

			for(int j = 0; j < sum_str.size() || j < a[2].size(); j++) {
				if(j < sum_str.size() && j >= a[2].size()) {
					if(sum_str[sum_str.size() - 1 - j] != '0')
						flag = false;
				}
				else if(j >= sum_str.size() && j < a[2].size()) {
					if(a[2][a[2].size() - 1 - j] != '0')
						flag = false;
				}
				else {
					if(sum_str[sum_str.size() - 1 - j] != a[2][a[2].size() - 1 - j])
						flag = false;
				}
			}

			if(flag) {
				ans = i;
				break;
			}
		}

		if(ans == -1)
			cout << "NA" << endl;
		else
			cout << ans << endl;
	}

	return 0;
}