#include <iostream>
using namespace std;

int dx[3] = {-1,0,+1};

int main(){
	int w, h, s[20][20];
	while( cin >> w >> h, w || h ){
		for(int y=0 ; y < h ; y++ ){
			for(int x=0 ; x < w ; x++ ){
				cin >> s[y][x];
			}
		}
		
		int dp[20][20] = {0};
		for(int x=0 ; x < w ; x++ ){
			if( s[0][x] == 0 ) dp[0][x] = 1;
		}
		for(int y=0 ; y < h-1 ; y++ ){
			for(int x=0 ; x < w ; x++ ){
				if( s[y][x] == 0 ){
					for(int i=0 ; i < 3 ; i++ ){
						int mx = x + dx[i];
						int my = y + 1;
						if( mx < 0 || mx >= w ) continue;
						
						if( s[my][mx] == 0 ){
							dp[my][mx] += dp[y][x];
						}else if( i == 1 && s[my][mx] == 2 ){
							dp[my][mx] += dp[y][x];
						}
					}
				}else if( s[y][x] == 2 ){
					int mx = x;
					int my = y + 2;
					if( s[my][mx] != 1 ){
						dp[my][mx] += dp[y][x];
					}
				}
			}
		}
		
		int ans=0;
		for(int x = 0 ; x < w ; x++ ){
			ans += dp[h-1][x] + dp[h][x];
		}
		cout << ans << endl;
	}
}