#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <fstream>
#include <numeric>
#include <algorithm>

using namespace std;

int main(int argc, char **argv) {
  int x, y, **field, **route, rsum;

  while (true) {
    cin >> x >> y;
    if (x == 0 && y == 0)
      break;
    rsum = 0;
    field = new int*[y];
    route = new int*[y];
    for (int i = 0; i < x; i++) {
      field[i] = new int[x];
      route[i] = new int[x];
      memset(route[i], 0, sizeof(int) * x);
    }
    for (int i = 0; i < y; i++)
      for (int j = 0; j < x; j++)
        cin >> field[i][j];
    for (int i = 0; i < x; i++) {
      int f = field[0][i];
      if (!f)
        route[0][i] = 1;
    }

    for (int i = 1; i < y; i++)
      for (int j = 0; j < x; j++) {
        int f = field[i][j];
        if (f == 0) {
          for (int k = -1; k <= 1; k++)
            if ((j + k >= 0 && j + k < x) &&
                ((k == 0 && field[i-1][j+k] == 2) ||
                 (field[i-1][j+k] != 2)))
              route[i][j] += route[i-1][j+k];
        } else if (f == 1) {
          route[i][j] = 0;
        } else if (i + 2 < y) {
          route[i+2][j] = route[i-1][j];
        } else if (i + 2 >= y) {
          rsum += route[i-1][j];
        }
      }
    for (int i = 0; i < x; i++)
      rsum += route[y-1][i];

    cout << rsum << endl;
    /* for DEBUG */
    for (int i = 0; i < y; i++) {
      for (int j = 0; j < x; j++) {
        cout << route[i][j];
        cout << ' ';
      }
      cout << endl;
    }

  }
  return 0;
}