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:              #  ?????????????????°?????´?????????????????????????????????
            k = '{}_{}'.format(x, 0)
            Q.append((x, 0))
            path[k] = 1

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

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

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

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


def solve2(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

    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(3):      #  ?????????3???len(dy)?????????
            nx = cx + dx[i]     #  ?????°????????§?¨?
            ny = cy + dy[i]

            if 0<= nx < x_limit:
                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:
                    if (ny >= y_limit - 1):
                        ans += num
                    else:
                        t = '{}_{}'.format(nx, ny)
                        if not path[t]:
                            Q.append((nx, ny))
                        path[t] += num
    return ans


def solve3(field):
    BLANK, OBSTACLE, JUMP = 0, 1, 2
    X = len(field[0])
    Y = len(field)
    dp = [[0] * X for _ in range(Y)]

    # ??????????????°????????????
    for x in range(X):
        if field[0][x] == BLANK:
            dp[0][x] = 1

    for y in range(1, Y):
        for x in range(X):
            t = 0
            mark = field[y][x]
            if mark == BLANK:
                if field[y-1][x] != JUMP:
                    t += dp[y-1][x]
                if x > 0 and field[y-1][x-1] != JUMP:
                    t += dp[y-1][x-1]
                if x < X-1 and field[y-1][x+1] != JUMP:
                    t += dp[y-1][x+1]
                if y > 1 and field[y-2][x] == JUMP:
                    t += dp[y-2][x]
            elif mark == JUMP:
                t = dp[y-1][x]
                if y > 1 and field[y-2][x] == JUMP:
                    t += dp[y-2][x]
            dp[y][x] = t
    ans = sum(dp[-1])
    if Y > 1:
        for x in range(X):
            if field[-2][x] == JUMP:
                ans += dp[-2][x]
    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 = solve3(field)
        print(result)


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