#include <iostream>
#include <cstring>
using namespace std;

int X, Y;
int map[20][20], dp[20][20][20];

int rec(int x, int y, int prevx){

  if(x < 0 || x > X-1) return 0;
  if(map[y][x] == 1) return 0;
  if(y >= Y-1) return 1;
  if(dp[y][x][prevx]) return dp[y][x][prevx];

  int ret = 0;
  if(map[y][x] == 0){
    ret = rec(x-1, y+1, x) + rec(x, y+1, x) + rec(x+1, y+1, x);
  }
  if(map[y][x] == 2 && prevx == x){
    ret = rec(x, y+2, x);
  }

  return dp[y][x][prevx] = ret;

}

int main(){

  while(cin >> X >> Y, X||Y){

    memset(dp, 0, sizeof(dp));
    for(int i = 0; i < Y; i++){
      for(int j = 0; j < X; j++) cin >> map[i][j];
    }

    int ans = 0;
    for(int i = 0; i < X; i++)
      ans += rec(i, 0, i);

    cout << ans << endl;
  }

}