#include <iostream>
#include <algorithm>
using namespace std;
#define MAX 15

int memo[MAX][MAX];
int X, Y;
int data[MAX][MAX];

int rec(int x, int y) {
  static int d[3][2] = {{-1,1},{0,1},{1,1}};

  if(memo[y][x] == -1) {
    memo[y][x] = 0;
    if(y == Y-1) {
      memo[y][x] += 1;
    } else if(data[y][x] == 2) {
      int nx = x;
      int ny = y+2;
      if(ny >= Y) {
	memo[y][x] += 1;
      } else {
	if(data[ny][nx] != 1)
	  memo[y][x] += rec(nx, ny);
      }
    } else {
      for(int i = 0; i < 3; i++) {
	int nx = x + d[i][0];
	int ny = y + d[i][1];
	if(nx < 0 || nx >= X) continue;
	if(data[ny][nx] == 1) continue;
	if(i != 1 && data[ny][nx] == 2) continue;
	memo[y][x] += rec(nx, ny);
      }
    }
  }
  return memo[y][x];
}

main() {
  while(1) {
    cin >> X >> Y;
    if(X == 0 && Y == 0) break;
    for(int i = 0; i < Y; i++) {
      for(int j = 0; j < X; j++) {
	cin >> data[i][j];
	memo[i][j] = -1;
      }
    }
    
    int cnt = 0;
    for(int j = 0; j < X; j++) {
      if(data[0][j] == 0) 
	cnt += rec(j, 0);
    }
    /*for(int i = 0; i < Y; i++) {
      for(int j = 0; j < X; j++) {
	cout << memo[i][j] << ' ';
      }
      cout << endl;
      }
      cout << endl;*/
    cout << cnt << endl;
  }
}