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

#define f first
#define s second
#define mp make_pair

#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()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int w,h;
  while(cin>>w>>h, w+h){
    int f[h][w];
    long long ans[h+2][w];
    memset(ans, 0, sizeof(ans));
    REP(i,h) REP(j,w) cin>>f[i][j];
    REP(i,w) if(f[0][i] == 0) ans[0][i] = 1;
    REP(i,h) REP(j,w){
      if(ans[i][j] != 0){
        int y = i + (f[i][j]==2?2:1);
        REP(k,3){
          if((f[i][j]==2 || i == h - 1) && k!=1) continue;
          int x = j + k - 1;
          if(x < 0 || x >= w) continue;
          if(y >= h || f[y][x] == 0)
            ans[y][x] += ans[i][j];
          else if(k == 1 && f[y][x] == 2)
            ans[y][x] += ans[i][j];
        }
      }
    }
    //REP(i,h+2){REP(j,w)printf("%lld ",ans[i][j]); puts("");}
    long long sum = 0;
    REP(i,2) REP(j,w) sum += ans[h+i][j];
    cout << sum << endl;
  }
  return 0;
}