#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;

enum FState { PLAIN, TREE, JUMP };
enum PState { LAND, AIR };

int field[17][16];
int dp[17][16][2];

int main() {
  int x, y;
  while (cin >> x >> y, x) {
    for (int yi = 1; yi <= y; yi++) {
      for (int xi = 1; xi <= x; xi++) {
        cin >> field[xi][yi];
      }
      field[0][yi] = field[x + 1][yi] = TREE;
    }

    for (int xi = 1; xi <= x; xi++) {
      dp[xi][1][LAND] = field[xi][1] == TREE ? 0 : 1;
      dp[xi][1][AIR] = 0;
    }
    for (int yi = 2; yi <= y; yi++) {
      for (int xi = 1; xi <= x; xi++) {
        // AIR
        dp[xi][yi][AIR] = field[xi][yi - 1] == JUMP ? dp[xi][yi - 1][LAND] : 0;
        // LAND
        auto& ldp = dp[xi][yi][LAND];
        switch (field[xi][yi]) {
        case PLAIN:
          ldp = dp[xi][yi - 1][AIR];
          for (int offset : {-1, 0, 1}) {
            if (field[xi + offset][yi - 1] == PLAIN) ldp += dp[xi + offset][yi - 1][LAND];
          }
          break;
        case TREE:
          ldp = 0;
          break;
        case JUMP:
          ldp = dp[xi][yi - 1][AIR];
          if (field[xi][yi - 1] == PLAIN) ldp += dp[xi][yi - 1][LAND];
          break;
        }
      }
    }
    
    int r = 0;
    for (int xi = 1; xi <= x; xi++) {
      r += dp[xi][y][LAND] + dp[xi][y][AIR];
    }
    cout << r << endl;
  }
  return 0;
}