#include <iostream>
using namespace std;

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 dp[20][20] = {0};
		for(int x=1 ; x <= w ; x++ )
			dp[1][x] = 1;
		for(int y=2 ; y <= h ; y++ ){
			for(int x=1 ; x <= w ; x++ ){
				if( f[y][x] == 0 ){
					if( f[y-1][x-1] == 0 ) dp[y][x] += dp[y-1][x-1];
					if( f[y-1][x]   == 0 ) dp[y][x] += dp[y-1][x];
					if( f[y-1][x+1] == 0 ) dp[y][x] += dp[y-1][x+1];
					if( f[y-2][x]   == 2 ) dp[y][x] += dp[y-2][x];
				}else if( f[y][x] == 2 ){
					if( f[y-1][x] == 0 ) dp[y][x] += dp[y-1][x];
					if( f[y-2][x] == 2 ) dp[y][x] += dp[y-2][x];
				}
			}
		}
		int ans = 0;
		for(int x=1 ; x <= w ; x++ ){
			ans += dp[h][x];
			if( f[h-1][x] == 2 ){
				ans += dp[h-1][x];
			}
		}
		cout << ans << endl;
	}
}