#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main ( void )
{
	string in;
	
	while (cin >> in)
	{
		int ans = -1;
		
		for (int i = 0; i < 10; i += 1)
		{
			int value = 0;
			
			int ii, m;
			
			if (!i && in[0] == 'X')
				continue;
			
			for (ii = in.size() - 1, m = 1; in[ii] != '='; --ii, m *= 10)
			{
				value += ((in[ii] == 'X') ? (i * m) : ((in[ii] - '0') * m));
			}
			
			if (!i && in[ii+1] == 'X')
				continue;
				
			for (--ii, m = 1; in[ii] != '+'; --ii, m *= 10)
			{
				value -= ((in[ii] == 'X') ? (i * m) : ((in[ii] - '0') * m));
			}
			
			if (!i && in[ii+1] == 'X')
				continue;
			
			for (--ii, m = 1; ii >= 0; --ii, m *= 10)
			{
				value -= ((in[ii] == 'X') ? (i * m) : ((in[ii] - '0') * m));
			}
			
			if (!value)
			{
				ans = i;
				break;
			}
		}
		
		if (ans == -1)
			cout << "NA" << endl;
		else
			cout << ans << endl;
	}
	return 0;
}