
import std.stdio, std.ascii, std.conv, std.string, std.math;

bool check(char[] str, int i) {
  long res, state = 0, x = 0;
  int digit = 0, top = 0;
  bool mask = false;
  long[3] nums;
  foreach(s; str.dup.reverse) {
    long n;
    if (s == 'X') {
      n = i;
      top++;
      mask = true;
    }
    else if (isDigit(s)) {n = s - '0'; top = 0;}
    else {
      nums[state++] = x;
      x = 0;
      digit = 0;
      if (top > 0 && i == 0) return false;
      continue;
    }
    x += pow(10, digit) * n;
    digit++;
  }
  if (!mask) return false;
  nums[state] = x;
  return (nums[0] == nums[1] + nums[2]);
}

void main() {
  string line;
  while ((line = readln) != null) {
    char[] expr = line.chomp.dup.to!(char[]);
    int ans = -1;
    for(int i = 0; i <= 9; i++) {
      if (check(expr, i)) {
        ans = i;
        break;
      }
    }
    writeln((ans >= 0) ? ans.to!(string) : "NA");
  }
}