#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
typedef long long Int;

int a[20][20];
int dp[20][20];

int main() {
  for (;;) {
      memset(dp, 0, sizeof(dp));
      memset(a, 0, sizeof(a));
      int C, R; cin >> C >> R;
      if ((C | R) == 0) break;
      REP(r, R) REP(c, C) cin >> a[r][c];


      REP(c, C) if (a[0][c] == 0) dp[0][c] = 1;
      REP(r, R - 1) {
          REP(c, C) if (a[r][c] == 0) {
              if (c - 1 >= 0) dp[r + 1][c - 1] += dp[r][c];
              if (c + 1 <  C) dp[r + 1][c + 1] += dp[r][c];
              if (a[r + 1][c] == 2) {
                  int d = 1;
                  while (a[r + d][c] == 2) d += 2;
                  dp[r + d][c] += dp[r][c];
              }
              else
                  dp[r + 1][c] += dp[r][c];
          }
      }

      Int ans = 0;
      REP(c, C) {
          if (a[R - 1][c] == 0) ans += dp[R - 1][c];
          if (a[R][c] == 0) ans += dp[R][c];
      }

      cout << ans << endl;

  }
  return 0;
}