#include <iostream>
#include <sstream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main(){
	int x,y;
	while(1){
		cin >> x >> y;
		if(x+y==0) break;
		int a[x][y];
		for(int j=0;j<y;j++) for(int i=0;i<x;i++) cin >> a[i][j];
		long long d[x][y];
		for(int i=0;i<x;i++) d[i][0] = 1 - a[i][0];
		for(int j=1;j<y;j++){
			for(int i=0;i<x;i++){
				if(a[i][j]==1) d[i][j] = 0;
				else if(a[i][j]==0){
					if(a[i][j-1]!=2) d[i][j] = d[i][j-1];
					if(i>0 and a[i-1][j-1]!=2) d[i][j] += d[i-1][j-1];
					if(i<x-1 and a[i+1][j-1]!=2) d[i][j] += d[i+1][j-1];
					if(j>1 and a[i][j-2]==2) d[i][j] += d[i][j-2];
				}
				else{
					d[i][j] = d[i][j-1];
					if(j>1 and a[i][j-2]==2) d[i][j] += d[i][j-2];
				}
			}
		}
		int s = 0;
		for(int i=0;i<x;i++){
			if(y>2 and a[i][y-2]==2) s += d[i][y-2];
			s += d[i][y-1];
		}
		cout << s << endl;
	}
}