import Data.Char

splitBy :: Char -> String -> [String]
splitBy _ [] = []
splitBy a x =
  let s = takeWhile (/= a) x
      x'= dropWhile (/= a) x
  in
    if x' == []
    then [s]
    else s:(splitBy a $ drop 1 x')

rep _ [] = []
rep c ('X':as) = (intToDigit c):(rep c as)
rep c (a:as)   = a:(rep c as)

apply n s =
  let x = rep n s
  in
    read x :: Int

try (-1) _ = -1
try n [a,b,c] =
  let na = apply n a
      nb = apply n b
      nc = apply n c
  in
    if na + nb == nc
    then n
    else try (n-1) [a,b,c]

ans str =
  let s = concat $ map (splitBy '=') $ splitBy '+' str
      a = try 9 s
  in
    if a /= -1
    then show(a)
    else "NA"

main = do
  c <- getContents
  let i = lines c
      o = map ans i
  mapM_ putStrLn o