#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;
static const int INF = (int)1e8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FIND(m,w) ((m).find(w)!=(m).end())
int w,h;
int grid[15][15];
int memo[15][15];
int dfs(int x,int y){
  if(x<0||x>=w) return 0;
  if(y<0||y>=h) return 0;
  if(grid[y][x]==1) return memo[y][x] = 0;
  if(y==0) return memo[y][x] = 1;
  if(memo[y][x]>=0){
    return memo[y][x];
  }
  int ret = 0;
  if(grid[y-1][x]!=2)ret += dfs(x,y-1);
  if(grid[y][x]!=2&&x-1>=0&&grid[y-1][x-1]!=2)ret += dfs(x-1,y-1);
  if(grid[y][x]!=2&&x+1<w&&grid[y-1][x+1]!=2)ret += dfs(x+1,y-1);
  if(y>=2&&grid[y-2][x]==2) ret += dfs(x,y-2);
  return memo[y][x] = ret;
}

int main(void){
  while(cin>>w>>h,w){
    memset(memo,-1,sizeof(memo));
    REP(y,h)REP(x,w){
      cin>>grid[y][x];
    }
    int ans = 0;
    REP(x,w){
      ans += dfs(x,h-1);
      if(grid[h-2][x]==2) ans += dfs(x,h-2);
    }
    
    cout<<ans<<endl;
  }
  return 0;
}