#include <iostream>
using namespace std;

int solve(int f[20][20] ,int w ,int h ){
	int dp[20][20] = {0};
	for(int x=1 ; x <= w ; x++ ){
		dp[1][x] = 1;
	}

	for(int y=1 ; y <= h-1 ; y++ ){
		for(int x=1 ; x <= w ; x++ ){
			if( f[y][x] == 0 ){
				if( f[y+1][x-1] == 0 ) dp[y+1][x-1] += dp[y][x];
				if( f[y+1][x]   == 0 ) dp[y+1][x]   += dp[y][x];
				if( f[y+1][x+1] == 0 ) dp[y+1][x+1] += dp[y][x];
				if( f[y+1][x]   == 2 ) dp[y+1][x]   += dp[y][x];
			}else if( f[y][x] == 2 ){
				if( f[y+2][x] == 0 || f[y+2][x] == 2 ){
					dp[y+2][x] += dp[y][x];
				}
			}
		}
	}
	int ans = 0;
	for(int x=1 ; x <= w ; x++ ){
		ans += dp[h][x] + dp[h+1][x];
	}
	return ans;
}

int main(){
	int w,h;

	while( cin >> w >> h , w||h ){
		int f[20][20] = {0};
		for(int y=1 ; y <= h ; y++ ){
			for(int x=1 ; x <= w ; x++ ){
				cin >> f[y][x];
			}
		}

		int ans = solve( f , w , h );
		cout << ans << endl;
	}
}