#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int dx[] = {-1,0,1},dy[] = {1,1,1};
int main(){
	int x,y;
	while(cin >> x >> y,x,y){
		int field[20][20] = {{0}};
		int dp[20][20] = {{0}};
		for(int i = 0; i < 20; i++)for(int j = 0; j < 20; j++)field[i][j] = 1;
		for(int i = 1; i <= y; i++){
			for(int j = 1; j <= x; j++){
				cin >> field[i][j];
			}
		}
		for(int i = 1; i <= x; i++){
			if(field[1][i] == 0)dp[1][i] = 1;
		}
		int sum = 0;
		for(int i = 1; i <= y; i++){
			for(int j = 1; j <= x; j++){
				if(field[i][j] == 0){
					for(int k = 0; k < 3; k++){
						int px = j + dx[k],py = i + dy[k];
						if((field[py][px] == 2 && k == 1) || field[py][px] == 0){
							dp[py][px] += dp[i][j];
						}
					}
				}
				else if(field[i][j] == 2){
					if(i == y-1)sum += dp[i][j];
					else{
						if(field[i+2][j] != 1)dp[i+2][j] += dp[i][j];
					}
				}
			}
		}
		for(int i = 1; i <= x; i++){
			sum += dp[y][i];
		}
		printf("%d\n",sum);
	}
	return 0;
}