#include<iostream>
using namespace std;

int main(){
  int x,y;
  int grid[16][15];
  int c[16][15];
  int dx[] = {-1,0,1};

  for(;;){
    cin >> x >> y;
    if(!x && !y)break;

    for(int i=0;i<y;i++)
      for(int j=0;j<x;j++)cin >> grid[i][j];
    for(int j=0;j<x;j++)grid[y][j] = 0;

    for(int i=0;i<y+1;i++)
      for(int j=0;j<x;j++)c[i][j] = 0;

    for(int i=0;i<x;i++)
      if(!grid[0][i])c[0][i] = 1;

    for(int i=0;i<y-1;i++){
      for(int j=0;j<x;j++){
	if(!grid[i][j]){
	  for(int k=0;k<3;k++){
	    int sx = j+dx[k];
	    if(sx<0 || x<=sx)continue;
	    if(!grid[i+1][sx] || (grid[i+1][sx]==2 && k==1))c[i+1][sx] += c[i][j];
	  }
	}
	if(grid[i][j] == 2){
	  if(grid[i+2][j]!=1)c[i+2][j] += c[i][j];
	}
      }
    }

    int ans = 0;
    for(int i=0;i<x;i++){
      ans += c[y-1][i];
      ans += c[y][i];
    }
    /*
    for(int i=0;i<y+2;i++){
      for(int j=0;j<x;j++)cout << c[i][j] << " ";
      cout << endl;
    }
    */
    cout << ans << endl;
  }
}