#include <cstdio>
#include <cstring>
#define NORMAL 0
#define TREE 1
#define JUMP 2
#define DR_NUM 3 // 方向数

using namespace std;

const int dy[DR_NUM] = {1,1,1}, dx[DR_NUM] = {-1,0,1};

int main(void){
	int x, y, course[15][15], dp[17][15], i, j, k, l, ans;
	while(1){
		scanf("%d%d",&x,&y);
		if(x == 0 && y == 0){
			break;
		}
		for(i = 0;i < y;i++){
			for(j = 0;j < x;j++){
				scanf("%d",&course[i][j]);
			}
		}
		memset(dp,0,sizeof(dp));
		for(i = 0;i < x;i++){
			if(course[0][i] != TREE)
				dp[0][i] = 1;
		}
		for(j = 0;j < y;j++){
			for(k = 0;k < x;k++){
				if(course[j + 2][k] != TREE && (course[j][k] == JUMP || j == y - 1)){
					dp[j + 2][k] += dp[j][k];
				}else if(course[j][k] == NORMAL){
					for(l = 0;l < DR_NUM;l++){
						if(k + dx[l] >= 0 && k + dx[l] < x && course[j + dy[l]][k + dx[l]] != TREE && !(l != 1 && course[j + dy[l]][k + dx[l]] == JUMP)){
							dp[j + dy[l]][k + dx[l]] += dp[j][k];
						}
					}
				}
			}
		}
		ans = 0;
		for(i = 0;i < x;i++){
			ans += dp[y][i] + dp[y + 1][i];
		}
		printf("%d\n",ans);
	}
	return 0;
}