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

int getNumber( string& formula, int* index, int n )
{
	int ret = 0;
	for( ; ; ++*index ){
		if( formula[ *index ] >= '0' && formula[ *index ] <= '9' ){
			ret *= 10;
			ret += ( formula[ *index ] - '0' );
		}else if( formula[ *index ] == 'X' ){
			ret *= 10;
			ret += n;
		}else{
			break;
		}
	}

	return ret;
}

int main()
{
	string formula;

	while( cin >> formula ){
		bool find = false;
		for( int i = 0; i < 10; ++i ){
			int index = 0;
			int res = 0;
			bool equal = false;
			while( index < (int)formula.size() ){
				if( ( formula[ index ] >= '0' && formula[ index ] <= '9' )
					|| ( i != 0 && formula[ index ] == 'X' ) ){
						if( !equal ){
							res += getNumber( formula, &index, i );
						}else{
							res -= getNumber( formula, &index, i );
							if( res == 0 ){
								find = true;
								break;
							}
						}
				}else{
					if( formula[ index ] == '=' ){
						equal = true;
					}
					++index;
				}
			}
			if( find ){
				cout << i << endl;
				break;
			}
		}
		if( !find ){
			cout << "NA" << endl;
		}
	}
	return 0;
}