#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

const int EMPTY = -1;
const int MOVE = 0;
const int BARRIIER = 1;
const int JUMP = 2;

int course[15][15];
int sizeX, sizeY;
int answer = 0;

void initCourse() {
  for (int i = 0; i < 15; i++) {
    for (int j = 0; j < 15; j++) {
      course[i][j] = EMPTY;
    }
  }
}

void inputCourse() {
  for (int i = 0; i < sizeY; i++) {
    for (int j = 0; j < sizeX; j++) {
      cin >> course[i][j];
    }
  }
}

void move(int x, int y) {
  if (course[y][x] == BARRIIER) {
    return;
  }
  if (y >= sizeY - 1) {
    answer++;
    return;
  }
  if (course[y][x] == JUMP) {
    move(x, y + 2);
  }
  if (course[y][x] == MOVE) {
    if ((x - 1) >= 0) {
      if (course[y + 1][x - 1] == MOVE) {
        move(x - 1, y + 1);
      }
    }
    if (course[y + 1][x] == MOVE || course[y + 1][x] == JUMP) {
      move(x, y + 1);
    }
    if ((x + 1) < sizeX) {
      if (course[y + 1][x + 1] == MOVE) {
        move(x + 1, y + 1);
      }
    }
  }
}

int main(int argc, char* argv[]) {
  while (cin >> sizeX >> sizeY, sizeX) {
    initCourse();
    inputCourse();
    answer = 0;
    for (int i = 0; i < sizeX; i++) {
      if (course[0][i] == MOVE) {
        move(i, 0);
      }
    }
    cout << answer << endl;
  }
  return 0;
}