#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;

#define MAX 17
#define f first
#define s second
typedef pair<int, int> P;

int X, Y;
int field[MAX][MAX];
int dp[MAX][MAX];

int solve(){
  for(int i = 0 ; i < Y ; i++){
    for(int j = 0 ; j <= X ; j++){
      if(field[i][j] == 0){
	for(int dx = -1 ; dx <= 1 ; dx++){
	  if(field[i+1][j+dx] != 1 && (field[i+1][j+dx] == 0 || dx == 0)){
	    dp[i+1][j+dx] += dp[i][j];
	  }
	}
      }
      else if(field[i][j] == 2 && field[i+2][j] != 1){
	dp[i+2][j] += dp[i][j];
      }
    }
  }

  int res = 0;
  for(int i = 0 ; i <= X ; i++){
    res += dp[Y][i] + dp[Y+1][i];
  }
  return res;
}

void init(){
  memset(dp, 0, sizeof(dp));
  for(int i = 0 ; i <= X ; i++){
    if(field[0][i] == 0) dp[0][i] = 1;
  }
}

int main(){
  while(cin >> X >> Y, X && Y) {
    X--, Y--;
    for(int i = 0 ; i <= Y ; i++) {
      for(int j = 0 ; j <= X ; j++) {
	cin >> field[i][j];
      }
    }
    
    init();
    cout << solve() << endl;
  }
  return 0;
}