#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

int main(){

	int width,height,map[17][17],table[17][17],sum;

	while(true){
		scanf("%d %d",&width,&height);
		if(width == 0 && height == 0)break;

		for(int i = 0; i < 17; i++){
			for(int k = 0; k < 17; k++){
				table[i][k] = 0;
				map[i][k] = 2;
			}
		}

		for(int i = 1; i <= height; i++){
			for(int k = 1; k <= width; k++){
				scanf("%d",&map[i][k]);
				if(map[i][k] == 0){
					if(i == 1){
						table[i][k] = 1;
					}else{
						if(map[i-1][k-1] != 2){
							table[i][k] += table[i-1][k-1];
						}
						if(map[i-1][k] != 2){
							table[i][k] += table[i-1][k];
						}
						if(map[i-1][k+1] != 2){
							table[i][k] += table[i-1][k+1];
						}
						if(map[i-2][k] == 2){
							table[i][k] += table[i-2][k];
						}
					}
				}else if(map[i][k] == 1){
					table[i][k] = 0;
				}else{
					if(map[i-1][k] != 2){
						table[i][k] += table[i-1][k];
					}
					if(map[i-2][k] == 2){
						table[i][k] += table[i-2][k];
					}
				}
			}
		}

		sum = 0;

		for(int k = 1; k <= width; k++){
			sum += table[height][k];
			if(map[height-1][k] == 2){
				sum += table[height-1][k];
			}
		}

		printf("%d\n",sum);
	}

	return 0;
}