#include<iostream>
using namespace std;
inline bool isinside(int j, int X){ return 0<=j&&j<X; }
int main()
{
  while(true){
    int X,Y;
    cin >> X >> Y;
    if( X == 0 && Y == 0 ) break;
    int M[Y][X];
    long long int ans[Y+2][X];
    for(int i = 0; i < Y; ++i){
      for(int j = 0; j < X; ++j){
	int c;
	cin >> c;
	M[i][j]=c;
	ans[i][j]=0;
      }
    }
    for(int i = 0; i < X; ++i){
      ans[Y][i] = ans[Y+1][i] = 1;
    }
    const int dx[]={-1,0,1};
    for(int i = Y-1; i >= 0; --i){
      for(int j = 0; j < X; ++j){
	if( M[i][j] == 1 ){
	  ans[i][j] = 0;
	}
	if( M[i][j] == 0 ){
	  for(int k = 0; k < sizeof(dx)/sizeof(*dx); ++k){
	    if( isinside( j + dx[k], X ) ){
	      //if( ans[i][j] == 0 ){
	      //ans[i][j] = ans[i+1][j+dx[k]];
	      //}else{
	      if( M[i+1][j+dx[k]] == 2 && dx[k]!=0 )continue;
		ans[i][j] += ans[i+1][j+dx[k]];
		//}
	    }
	  }
	}
	if( M[i][j] == 2 ){
	  ans[i][j] = ans[i+2][j];
	}
	if( i == Y-1 && ans[i][j] > 0 )ans[i][j] = 1;
	//cout << ans[i][j] << ' ';
      }
      //cout << endl;
    }
    long long int Answer = 0;
    for(int i = 0; i < X; ++i){
      Answer += ans[0][i];
    }
    cout << Answer << endl;
  }
  return 0;
}