object Main {
    def main(args: Array[String]): Unit = {
        val in = io.StdIn.readLine.split(" ").map(_.toInt)
        println(((1 to 9) diff in).permutations.map(p => {
            p.foldLeft(in)((arr, n) => arr.updated(arr.indexOf(-1), n))
        }).count(n => n(0)+n(1)*10+n(2)+n(3)*100+n(4)*10+n(5) == n(6)*100+n(7)*10+n(8)))
    }
}