while line = gets
    line = line.chomp.split('+')
    line[1, 2] = line[1].split('=')
    line.map!{|item| item.reverse}
    match = false
    0.upto(9){|x|
        satan = false
        item = [0, 0, 0]
        line.each_with_index{|y, i|
            y.split('').each_with_index{|c, keta|
                case c
                when 'X'
                    if keta == y.length - 1 && x == 0
                        satan = true
                        break
                    else
                        item[i] += (x * (10 ** keta))
                    end
                else
                    item[i] += (c.to_i * (10 ** keta))
                end
            }
            break if satan
        }
        next if satan
        if item[0] + item[1] == item[2]
            match = x
            break
        end
    }
    puts match ? match : "NA"
end
