#include<iostream>
#include<cstring>
using namespace std;
int X, Y;
int c[17][17];
int dp[17][17];
int solve(int x, int y, int bx);
int main(){
  long long int ans;
  while(1){
    ans = 0;
    cin >> X >> Y;
    if(X == 0 && Y == 0) break;
    memset(dp, 0, sizeof(dp));
    for(int i = 0; i < Y; i++){
      for(int j = 0; j < X; j++){
	cin >> c[i][j];
      }
    }
    for(int i = 0; i < X; i++){
      ans += solve(i, 0, i); 
    }
    cout << ans << endl;
  }
}

int solve(int x, int y, int bx){
  if(x < 0 || x >= X || c[y][x] == 1 || c[y][x] == 2 && x != bx) return 0;
  if(y >= Y - 1) return 1;
  if(dp[y][x] > 0) return dp[y][x];
  if(bx == x && c[y][x] == 2) return solve(x, y + 2, x);
  else if(c[y][x] == 0) return dp[y][x] = solve(x - 1, y + 1, x) + solve(x, y + 1, x) + solve(x + 1, y + 1, x);
}