Problem: The problem of hiding a part of a formula and searching for the hidden number is called verbal arithmetic. This time, I'm dealing with an expression in which some numbers in the expression are hidden by X. Enter the following formula and create a program that outputs the result.

Formula

* A simple one-line addition expression in the form of "number string + number string = number string".
* A "number sequence" is a sequence of numbers 0-9 and the letter X.
* It is assumed that the leftmost number in the "number string" with two or more digits is not 0.
* X must be at least one in the entire formula.



result

* The answer to the verbal arithmetic. It is one of 0 to 9 with a value of X such that the formula holds. Suppose there are no more than one answer.
* If there is no answer, the result should be “NA”.



Input

Given multiple datasets. For each dataset, an addition expression containing one or more Xs (a string of up to 126 characters without spaces) is given on one line. The number of datasets does not exceed 150.

Output

For each data set, output the result of the verbal arithmetic on one line. Print the numbers 0-9 or NA.

Example

Input

123+4X6=X79
12X+4X6=X79
XX22+89=X2XX


Output

5
NA
1

Solution (in CPP):

Solution:
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
using namespace std;

/*
  AOJ :: 0110
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0110
  Wrong Answer.
 */

char in[3][130];

bool iseq(){
    int tmp[130];
    int na = strlen(in[0]), nb = strlen(in[1]), nc = strlen(in[2]);
    int i;

    memset(tmp, 0, sizeof(tmp));
    for(i=0; i<na; i++) tmp[i] += in[0][na-i-1] - '0';
    for(i=0; i<nb; i++) tmp[i] += in[1][nb-i-1] - '0';
    for(i=1; i<130; i++){
        tmp[i] += tmp[i-1] / 10;
        tmp[i-1] %= 10;
    }

    for(i=0; i<nc; i++){
        if( tmp[i] != in[2][nc-i-1] - '0' ) return false;
    }
    for(; i<130; i++) if( tmp[i] != 0 ) return false;
    return true;
}

bool ischeck(int n, int p, int num){
    int i;
    bool res = false;

    if( n == 3 ){ // end
        return iseq();
    }

    if( in[n][p] == '\0' ){ // next str
        return ischeck(n+1, 0, num);
    }

    if( in[n][p] == 'X' ){
        if( p == 0 && num == 0 && strlen(in[n]) > 1 ) return false;
        in[n][p] = num + '0';
        res = ischeck(n, p+1, num);
        in[n][p] = 'X';
    }
    else{
        res = ischeck(n, p+1, num);
    }
    return res;
}

int main(){
    int num;

    while( ~scanf(" %[^+]+%[^=]=%s ", in[0], in[1], in[2]) ){
        for(num=0; num<=9; num++){
            if( ischeck(0, 0, num) ) break;
        }
        if( num > 9 ){
            puts("NA");
        }
        else{
            printf("%d\n",num);
        }
    }

    return 0;
}