#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int x,y;
  while(cin>>x>>y,x+y){
    int Map[y+10][x+10]={};
    int Map2[y+10][x+10]={};
    for(int i=0;i<y;i++)
      for(int j=0;j<x;j++){
	cin>>Map2[i][j];
	if(i==0&&Map2[i][j]==0)
	  Map[i][j]=1;
      }
    for(int i=0;i<y-1;i++){
      for(int j=0;j<x;j++){
	if(Map2[i][j]==0){
	  if(Map2[i+1][j+1]==0)
	    Map[i+1][j+1]+=Map[i][j];
	  if(Map2[i+1][j]!=1)
	    Map[i+1][j]+=Map[i][j];
	  if(j-1>=0&&Map2[i+1][j-1]==0)
	    Map[i+1][j-1]+=Map[i][j];
	}else if(Map2[i][j]==2){
	  if(Map2[i+2][j]!=1)
	    Map[i+2][j]+=Map[i][j];
	}
      }
    }
    ll ans=0;
    for(int i=y-1;i<=y;i++)
      for(int j=0;j<x;j++)
	ans+=Map[i][j];
    cout<<ans<<endl;
  }
  return 0;
}
  