#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

int X, Y;
int ba[15][15];

int const dx[] = {-1,0,1};
int solve(int x, int y) {
  if (y >= Y-1) return 1;
  int res = 0;
  REP(i,3) {
    int xx = x + dx[i];
    int yy = y+1;
    
    if (xx < 0 || X <= xx) continue;
    if (i == 1) {
      while (yy < Y && ba[xx][yy] == 2) {
        yy+=2;
      }
      if (yy >= Y || ba[xx][yy] == 0)
        res += solve(xx, yy);
    } else if (ba[xx][yy] == 0) {
      res += solve(xx, yy);
    }
  }
  return res;
}

int main() {
  while(cin >> X >> Y, X||Y) {
    REP(y,Y) {
      REP(x,X) {
        cin >> ba[x][y];
      }
    }
    int ans = 0;
    REP(x,X) {
      ans += solve(x, 0);
    }
    cout << ans << endl;
  }
}