#include <iostream>

using namespace std;

int C[15][15], dp[15][17];

int main() {
  for (;;) {
    int X, Y;
    cin >> X >> Y;
    if (!X && !Y) return 0;
    for (int y = 0; y < Y; y++)
      for (int x = 0; x < X+2; x++) {
        C[y][x] = 1;
        dp[y][x] = 0;
      }
    for (int y = 0; y < Y; y++)
      for (int x = 1; x <= X; x++)
        cin >> C[y][x];
    for (int x = 1; x <= X; x++)
      if (!C[0][x])
        dp[0][x] = 1;
    for (int y = 1; y < Y; y++)
      for (int x = 1; x <= X; x++) {
        switch (C[y][x]) {
        case 1:
          break;
        case 0:
          dp[y][x] += (C[y-1][x-1] ? 0 : dp[y-1][x-1]) +
                      (C[y-1][x+1] ? 0 : dp[y-1][x+1]);
        case 2:
          if (y >= 2 && C[y-2][x] == 2)
            dp[y][x] += dp[y-2][x];
          dp[y][x] += C[y-1][x] ? 0 : dp[y-1][x];
          break;
        default:
          break;
        }
      }
    int s = 0;
    for (int x = 1; x <= X; x++)
      s += dp[Y-1][x];
    if (Y >= 2)
      for (int x = 1; x <= X; x++)
        if (C[Y-2][x] == 2)
          s += dp[Y-2][x];
    cout << s << endl;
  }
}