#include <bits/stdc++.h>
using namespace std;
typedef string::iterator State;
string formula;
State it;

int calc(char num, char end) {
    int ret = 0;
    int weight = 0;
    while(*it != end) {
        //cout << "calculating..." << endl;
        char now = *it;
        if(now == 'X') now = num;
        ret += (now - '0') * pow(10, weight);
        if(it == formula.begin()) break;
        it--; weight++;
        
    }
    if(it != formula.begin()) it--; //endを飛ばす
    return(ret);
}

bool judge(char num) {
    it = formula.end() - 1;
    int ans = calc(num, '=');
    int sum = calc(num, '+') + calc(num, '*');
    return(sum == ans);
}

void solve() {
    char r = '0';
    if(formula[0] == 'X') r++;
    bool update = false;
    for(; r <= '9'; r++) {
        if(judge(r)) { update = true; printf("%d\n", r-'0'); return; }
    }
    if(!update) cout << "NA" << endl;
}

int main(void) {
    while(cin >> formula) {
        
        solve();
    }
    return(0);
}