#include<iostream>
#include<map>
#define pf p.first
#define ps p.second
using namespace std;
typedef pair<int,int>P;
int h,w,mas[20][20],memo[20][20],ans,tmp[]={-1,0,1};
int dfs(P);
int main(){
  while(cin >> w >> h && w||h){
    ans = 0;
    for(int i=0;i<20;i++) for(int j=0;j<20;j++) memo[i][j] = -1;
    for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin >> mas[i][j];
    for(int i=0;i<w;i++) ans += dfs(P(0,i));
    cout << ans << endl;
  }
}
int dfs(P p){
  if(memo[pf][ps] != -1) return memo[pf][ps];
  if(mas[pf][ps] == 1) return 0;
  if(pf >= h - 1) return 1;
  if(mas[pf][ps] == 2) return (memo[pf][ps] = dfs(P(pf+2,ps)));
  else{
    int cnt = 0;
    for(int i=0;i<3;i++){
      int nx = pf + 1,ny = ps + tmp[i];
      if(ny>=0&&ny<w&&((mas[nx][ny]==0)||(mas[nx][ny]==2&&i==1))){
	  cnt += dfs(P(pf+1,ps+tmp[i]));
	}
    }
    return (memo[pf][ps] = cnt);
  }
}