#include<iostream>
#define INF (1<<24)
using namespace std;

int compute(int a,int b,string str){
 
  int i=a,sum=0,tmp=INF,tmp2=INF,cnt=0;
  while(1){ //cout<<a<<' '<<b<<endl;
     
    sum=0;
    if(str[i]=='('){
      sum=compute(i+1,0,str);
      //cout<<sum<<endl;
      cnt=0;
      for(i=i;i<(int)str.size();i++){
    if(str[i]==')')cnt--;
    if(str[i]=='(')cnt++;
    if(cnt==0)break;
      }
      i++;
       
    }else{
      while(1){
    if('0'<=str[i]&&str[i]<='9'){
      sum*=10;
      sum+=(str[i]-'0');
      i++;
    }else{
      break;
    }
      }
    }
 
    if(b==1){
      sum*=-1;
      b=0;
    }
    if(tmp!=INF){
      sum*=tmp;
      tmp=INF;
    }
    if(tmp2!=INF){
      sum=tmp2/sum;
      tmp2=INF;
    }
    //if(a==8)cout<<sum<<endl;   
    if(str[i]=='\0'||str[i]==')'||str[i]=='='||i==(int)str.size())return sum;
    if(str[i]=='+')return sum + compute(i+1,0,str);
    if(str[i]=='-')return sum + compute(i+1,1,str);
    if(str[i]=='*'){
      i++;
      tmp=sum;
    }else if(str[i]=='/'){
      i++;
      tmp2=sum;
    }
  }
       
}


int main(){
  int x,A,B,i,f;
  string str,tmp;
  while(cin>>str){
    tmp=str;
    for(i=0;i<=9;i++){
      str=tmp;f=0;
      for(int j=0;j<(int)str.size();j++){
	if(i!=0&&str[j]=='X')str[j]='0'+i;
	if(i==0){
	  if(j!=0&&str[j-1]!='='&&str[j-1]!='+')str[j]='0';
	  else f=1;
	}
	if(str[j]=='=')x=j;
      }//j
      if(f)continue;
      A=compute(0,0,str.substr(0,x));
      B=compute(0,0,str.substr(x+1));
      //cout<<A<<' '<<B<<endl;
      if(A==B){
	cout<<i<<endl;
	break;
      }
    }//i
    if(i==10)cout<<"NA"<<endl;
  }
  return 0;
}