a = gets.split.map(&:to_i)
s = "%d+%d%d+%d%d%d==%d%d%d"
nums = (1..9).to_a - a.select {|x| x != -1}
if nums.empty?
    p eval(sprintf(s, *a)) ? 1 : 0
else
    k = 0
    nums.permutation(nums.size) do |perm|
        d = a.dup
        perm.each do |k|
            d[d.index{|x| x < 0}] = k
        end
        k += 1 if eval(sprintf(s, *d))
    end
    p k
end

