#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <map>
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 main() {
  
  int X, Y;
  int const dx[] = {0,-1,1};
  
  while(cin >> X >> Y, X||Y) {
    int ba[15][17] = {0};
    REP(y,Y) {
      REP(x,X) {
        cin >> ba[x][y];
      }
    }
    int dp[X][Y+2];
    memset(dp,0,sizeof(dp));
    REP(i,X) dp[i][0] = 1;
    for(int y=1; y<Y+2; ++y) {
      REP(x,X) {
        if (ba[x][y] == 0) {
          REP(i,((y<Y)?3:1)) {
            int xx = x + dx[i];
            int yy = y - 1;
    
            if (xx < 0 || X <= xx) continue;
            if (i == 0) {
              while (yy > 0 && ba[xx][yy-1] == 2) {
                yy-=2;
              }
              if (ba[xx][yy] == 0)
                dp[x][y] = dp[xx][yy]; 
            } else if (ba[xx][yy] == 0) {
              dp[x][y] += dp[xx][yy];
            }
          }
        }
      }
    }
    int ans = 0;
    REP(x,X)
      ans += dp[x][Y+1];
    cout << ans << endl;
  }
}