#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <stack>

using namespace std;

int main(){

	char buf[130];
	int left[9],right[9];
	int sum_l,sum_r,num_d,div_l,div_r;
	bool R_FLG;

	while(scanf("%s",buf)!=EOF){
		for(int i = 0; i < 9; i++){
			left[i] = 0;
			right[i] = 0;
		}

		sum_l = sum_r = 0;
		R_FLG = false;

		for(int i = 0; buf[i] != '\0'; ){
			for(num_d = 0;(buf[i+num_d] >= '0' && buf[i+num_d] <= '9') || (buf[i+num_d] == 'X');num_d++);

			for(int p = 0; p < num_d; p++){
				if(buf[i+p] == 'X'){
					if(!R_FLG){
						left[num_d-p-1]++;
					}else{
						right[num_d-p-1]++;
					}
				}else{
					if(!R_FLG){
						sum_l += (buf[i+p]-'0')*pow(10,num_d-p-1);
					}else{
						sum_r += (buf[i+p]-'0')*pow(10,num_d-p-1);
					}
				}
			}
			i+=num_d;
			if(buf[i] == '='){
				R_FLG = true;
			}
			i++;
		}

		bool Found = false;

		for(int i = 0; i <= 9; i++){
			div_l = div_r = 0;
			for(int k = 0; k <= 8; k++){
				div_l += pow(10,k)*i*left[k];
			}
			for(int k = 0; k <= 8; k++){
				div_r += pow(10,k)*i*right[k];
			}
			if(sum_l + div_l == sum_r + div_r){
				printf("%d\n",i);
				Found = true;
				break;
			}
		}
		if(!Found)printf("NA\n");
	}
	return 0;
}