#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int X, Y;
  while (cin >> X >> Y, X) {
    int c[20][20];
    int dp[20][20] = {};
    for (int i = 0; i < Y; i++) {
      for (int j = 0; j < X; j++) {
        cin >> c[i][j];
      }
    }
    for (int i = 0; i < X; i++) {
      if (c[0][i] == 0) dp[0][i] = 1;
    }
    for (int i = 0; i < Y - 1; i++) {
      for (int j = 0; j < X; j++) {
        if (c[i][j] == 0) {
          if (j > 0 && c[i + 1][j - 1] == 0) dp[i + 1][j - 1] += dp[i][j];
          if (c[i + 1][j] != 1) dp[i + 1][j] += dp[i][j];
          if (j + 1 < X && c[i + 1][j + 1] == 0) dp[i + 1][j + 1] += dp[i][j];
        } else if (c[i][j] == 2 && i + 2 < Y) {
          if (c[i + 2][j] != 1) dp[i + 2][j] += dp[i][j];
        }
      }
    }
    int ans = 0;
    for (int i = 0; i < X; i++) {
      if (c[Y - 2][i] == 2) ans += dp[Y - 2][i];
      ans += dp[Y - 1][i];
    }
    cout << ans << endl;
  }

  return 0;
}
