#include<iostream>
using namespace std;
int main(){
  while(true){
    int xsize,ysize;
    cin>>xsize>>ysize;
    if(!xsize&&!ysize)break;
    int course[xsize+2][ysize];
    for(int y=0;y<ysize;y++){
      for(int x=0;x<xsize;x++){
	cin>>course[x+1][y];
      }
    }
    int pattern[xsize+2][ysize+1];
    for(int y=0;y<ysize;y++){
      for(int x=0;x<xsize+2;x++){
	if(y) pattern[x][y] = 0;
	else if(course[x][y]) pattern[x][y] = 0;	    
	else pattern[x][y] = 1;
      }
    }
    pattern[0][0] = 0;
    pattern[xsize+1][0] = 0;
    int count = 0;
    for(int y=0;y<ysize;y++){
      for(int x=1;x<xsize+1;x++){
	cout<<pattern[x][y];
	if(course[x][y]==0){
	  if(y==ysize-1) count+=pattern[x][y];
	  else{
	    if(course[x-1][y+1]==0)
	      pattern[x-1][y+1] += pattern[x][y];
	    if(course[x][y+1]!=1)
	      pattern[x][y+1] += pattern[x][y];
	    if(course[x+1][y+1]==0)
	      pattern[x+1][y+1] += pattern[x][y];
	  }
	}
	if(course[x][y]==2){
	  if(y==ysize-2) count+= pattern[x][y];
	  else if(y==ysize-1) count+= pattern[x][y];
	  else pattern[x][y+2] += pattern[x][y];
	}
      }
      cout<<endl;
    }
    cout<<count<<endl;
  }
  return 0;
}