# -*- 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 cy > y_limit - 1:
            continue
        if field[cy][cx] == OBSTACLE:
            continue
        if 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

        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:])

### FIXED CODE ###

# -*- 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:
                if field[y-1][x] != 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:])