parse :: String -> [String]
parse xs = case break (== '+') xs of
    (y,ys) -> case break (== '=') (tail ys) of
        (z,zs) -> [y,z,tail zs]


split_impl :: String -> String -> String -> [String]
split_impl _ xs [] = [xs]
split_impl ds xs ys
    | ds == take (length ds) ys = xs : split_impl ds [] (drop (length ds) ys) 
    | otherwise = split_impl ds (xs ++ [head ys]) (tail ys)

split :: String -> String -> [String]
split ds xs = split_impl ds [] xs

join :: String -> [String] -> String
join ds = foldr1 ((++) . (++ ds))

replace :: String -> String -> String -> String
replace old new = join new . split old

toInt :: Int -> String -> Integer
toInt n = read . replace "X" (show n)

isOK :: Int -> [String] -> Maybe Int
isOK n xs = let [x,y,z] = map (toInt n) xs in if x + y == z then Just n else Nothing

solve :: String -> IO ()
solve xs = putStrLn $ maybe "NA" show $ foldr merge Nothing $ map (flip isOK (parse xs)) [0..9]
    where
        merge :: Maybe a -> Maybe a -> Maybe a
        merge Nothing x = x
        merge x _ = x

main :: IO ()
main = getContents
    >>= mapM_ solve . lines