#include<iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int main() {
  while (true) {
    int x, y;
    cin >> x >> y;
    if (x == 0 && y == 0) break;
    int c[20][20];
    rep (i, y) rep (j, x) cin >> c[i][j];
    long long dp[20][20][3] = {};
    rep (i, x) if (c[0][i] == 0) dp[0][i][1] = 1;
    rep (i, y - 1) rep (j, x) {
      if (c[i][j] == 0) {
	long long sum = dp[i][j][0] + dp[i][j][1] + dp[i][j][2];
	if (j > 0 && c[i + 1][j - 1] != 2) dp[i + 1][j - 1][0] += sum;
	dp[i + 1][j][1] += sum;
	if (c[i + 1][j + 1] != 2) dp[i + 1][j + 1][2] += sum;
      } else if (c[i][j] == 2) {
	dp[i + 2][j][1] += dp[i][j][1];
      }
    }
    long long res = 0;
    rep (i, x) if (c[y - 1][i] != 1) rep (k, 3) res += dp[y - 1][i][k];
    rep (i, x) res += dp[y][i][1];
    cout << res << endl;
  }
  return 0;
}