fun main(args:Array<String>?): Unit {
    while(true){
        val (x, y) = readLine()!!.trim().split(' ').map(String::toInt)
        if (x == 0 && y == 0) return
        val state = Array(y){
            readLine()!!.trim().split(' ').mapNotNull{
                when(it){
                    "0" -> State.Snow
                    "1" -> State.Barrier
                    "2" -> State.Jump
                    else -> null
                }
            }.toTypedArray()
        }
        println(
                solve(state)
        )
    }
}

fun sub(x: Int, y: Int, state: Array<Array<State>>, memo: Array<LongArray>): Long {
    return when{
        y !in state.indices || x !in state[y].indices || state[y][x] != State.Snow -> 0
        y == 0 -> 1
        memo[y][x] >= 0 -> memo[y][x]
        else -> {
            memo[y][x] = sub(x - 1, y - 1, state, memo) + sub(x, y - 1, state, memo) + sub(x + 1, y - 1, state,memo) + jumpFrom(x, y - 2, state, memo)
            memo[y][x]
        }
    }
}
fun jumpFrom(x: Int, y: Int, state: Array<Array<State>>, memo: Array<LongArray>): Long {
    return when{
        y !in state.indices || x !in state[y].indices || state[y][x] != State.Jump -> 0
        memo[y][x] >= 0 -> memo[y][x]
        else -> {
            memo[y][x] = jumpFrom(x, y - 2, state, memo) + sub(x, y - 1, state, memo)
            memo[y][x]
        }
    }
}
fun solve(state: Array<Array<State>>): Long {
    val memo = Array(state.size){LongArray(state[it].size){-1}}
    return state.last().indices.map{x -> sub(x, state.lastIndex, state, memo) + jumpFrom(x, state.lastIndex, state, memo) + jumpFrom(x, state.lastIndex - 1, state, memo)}.sum()
}
enum class State {
    Snow, Barrier, Jump
}
