#include<bits/stdc++.h>
using namespace std;

int main(){

  int x, y;
  while( cin >> x >> y, x+y ) {
    int field[16][16];
    int dp[16][16]={{0}};
    for(int i=0; i<y; i++) {
      for(int j=0; j<x; j++) {
	cin >> field[i][j];
      }
    }

    for(int i=0; i<x; i++) {
      if( field[0][i] != 1 ) dp[0][i] = 1;
    }


    for(int i=0; i<y-1; i++) {
      for(int j=0; j<x; j++) {
	if( field[i][j] == 1 ) continue;

	else if( field[i][j] == 2 ) {
	  if( field[i+2][j] != 1 ) {
	    dp[min(y-1, i+2)][j] += dp[i][j];
	  }
	}

	else {
	  if( j ) {
	    if( field[i+1][j-1] == 0 ) dp[i+1][j-1] += dp[i][j];
	  }
	  if( j < x-1 ) {
	    if( field[i+1][j+1] == 0 ) dp[i+1][j+1] += dp[i][j];
	  }
	  if( field[i+1][j] != 1 ) dp[i+1][j] += dp[i][j];
	}
      }
    }

    int sum = 0;
    for(int i=0; i<x; i++) {
      sum += dp[y-1][i];
    }

    cout << sum << endl;
  }
}