Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
	)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		X, _ := strconv.Atoi(buf[0])
		Y, _ := strconv.Atoi(buf[1])
		if X == 0 && Y == 0 {
			break
		}
		tbl := make([][]int, Y+2)
		field := make([][]int, Y+2)
		for i := range field {
			field[i] = make([]int, X+2)
			tbl[i] = make([]int, X+2)
			for j := range field[i] {
				field[i][j] = 2
				tbl[i][j] = 0
			}
		}
		buf_ := make([][]string, Y)
		for i := range buf_ {
			scanner.Scan()
			buf_[i] = strings.Split(scanner.Text(), " ")
		}
		for i := 1; i <= Y; i++ {
			for j := 1; j <= X; j++ {
				field[i][j], _ = strconv.Atoi(buf_[i-1][j-1])
				switch field[i][j] {
				case 0:
					if i == 1 {
						tbl[i][j] = 1 // スタートy=1
					} else {
						if field[i-1][j-1] != 2 {
							tbl[i][j] += tbl[i-1][j-1] // 左上からやってくる
						}
						if field[i-1][j] != 2 {
							tbl[i][j] += tbl[i-1][j] // 真上からやってくる
						}
						if field[i-1][j+1] != 2 {
							tbl[i][j] += tbl[i-1][j+1] // 右上からやってくる
						}
						if field[i-2][j] == 2 {
							tbl[i][j] += tbl[i-2][j] // ジャンプしてくる
						}
					}
				case 1:
					tbl[i][j] = 0 // 障害物あり
				case 2:
					if field[i-1][j] != 2 {
						tbl[i][j] += tbl[i-1][j] // 真上からくる
					}
					if field[i-2][j] == 2 {
						tbl[i][j] += tbl[i-2][j] // ジャンプ台からジャンプしてくる
					}
				}
			}
		}
		sum := 0
		for i := 1; i <= X; i++ {
			sum += tbl[Y][i] // とびこさないでゴール
			if field[Y-1][i] == 2 {
				sum += tbl[Y-1][i] // 飛び越してゴール
			}
		}
		fmt.Println(sum)
	}
}

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203

"""
import sys
from sys import stdin
from collections import deque, defaultdict
input = stdin.readline


def solve(field):
    BLANK, OBSTACLE, JUMP = 0, 1, 2
    ans = 0                     #  ??????????????°???????????°

    dy = [1, 1, 1]  # ?????????????????????????????????????§???????
    dx = [0, -1, 1]
    x_limit = len(field[0])
    y_limit = len(field)

    path = defaultdict(int)     #  ??????????????????????????°???????????°????????????'x???_y???'???????????????
    Q = deque()
    for x, m in enumerate(field[0]):
        if m == BLANK:              #  ?????????????????°?????´?????????????????????????????????
            t = '{}_{}'.format(x, 0)
            Q.append((x, 0))
            path[t] = 1
    if y_limit < 2:
        return len(Q)


    while Q:
        cx, cy = Q.popleft()        #  ?????¨??°?????§?¨?
        t = '{}_{}'.format(cx, cy)
        num = path.pop(t)

        if field[cy][cx] == OBSTACLE:
            continue
        elif field[cy][cx] == JUMP: #  ?????£????????§?????°?????????????????£????????°
            if cy+2 > y_limit-1:
                ans += num
            else:
                t = '{}_{}'.format(cx, cy+2)
                if not path[t]:
                    Q.append((cx, cy+2))
                path[t] += num
            continue
        elif cy == y_limit -1:
            ans += num
            continue

        for i in range(len(dx)):
            nx = cx + dx[i]     #  ?????°????????§?¨?
            ny = cy + dy[i]

            if 0<= nx < x_limit:
                if (ny >= y_limit - 1) and field[ny][nx] != OBSTACLE:
                    ans += num
                else:
                    if field[ny][nx] == JUMP and dx[i] == 0: #  ?????£????????°????????£??????????????\????????´???
                        if ny+2 > y_limit - 1:
                            ans += num
                        else:
                            t = '{}_{}'.format(nx, ny+2)
                            if not path[t]:
                                Q.append((nx, ny+2))
                            path[t] += num
                    elif field[ny][nx] == BLANK:
                        t = '{}_{}'.format(nx, ny)
                        if not path[t]:
                            Q.append((nx, ny))
                        path[t] += num
    return ans


def main(args):
    while True:
        X, Y = map(int, input().strip().split())
        if X == 0 and Y == 0:
            break
        field = []
        for _ in range(Y):
            temp = [int(x) for x in input().strip().split()]
            field.append(temp)
        result = solve(field)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Python: while 1:
    x,y = list(map(int, input().split()))
    if x == 0: break
    c = [list(map(int, input().split())) for _ in range(y)]
    c.append([0]*x)
    c.append([0]*x)
    dp = [[0]*x for _ in range(y+2)]
    for i in range(x):
        if c[0][i] == 0: dp[0][i] = 1
    for i in range(y):
        for j in range(x):
            if c[i][j] == 0:
                if i != y-1:
                    if j != 0 and c[i+1][j-1] == 0:
                        dp[i+1][j-1] += dp[i][j]
                    if j != x-1 and c[i+1][j+1] == 0:
                        dp[i+1][j+1] += dp[i][j]
                    if c[i+1][j] != 1:
                        dp[i+1][j] += dp[i][j]
            elif c[i][j] == 2:
                if c[i+2][j] != 1:
                    dp[i+2][j] += dp[i][j]
    ans = 0
    for i in dp[y-1:y+1]:
        ans += sum(i)
    print(ans)
"""
while 1:
    x,y = list(map(int, input().split()))
    if x == 0: break
    c = [list(map(int, input().split())) for _ in range(y)]
    dp = [[0]*x for _ in range(y+1)]
    for i in range(x):
        if c[0][i] == 0: dp[0][i] = 1
    for i in range(1,y):
        for j in range(x):
            if c[i][j] == 0:
                if i >= 2 and c[i-2][j] == 2:
                    dp[i][j] += dp[i-2][j]
                if j != 0   and c[i-1][j-1] == 0:dp[i][j] += dp[i-1][j-1]
                if j != x-1 and c[i-1][j+1] == 0:dp[i][j] += dp[i-1][j+1]
                if c[i-1][j] != 1: dp[i][j] += dp[i-1][j]
            elif c[i][j] == 2:
                dp[i][j] += dp[i-1][j]
                if i >= 2 and c[i-2][j] == 2:
                    dp[i][j] += dp[i-2][j]
    for i in dp:
        print(i)
    ans = 0
    for i in range(x):
        ans += dp[y-1][i]
        if y >= 2 and c[y-2][i] == 2:
            ans += dp[y-2][j]
    print(ans)
"""