#include <iostream>
using namespace std;
int w,h;
int mp[16][16];
int ans;
int count;

int saiki(int x,int y) {
  count++;
  // cout << x <<" "<<y <<endl;
  int dx[3] = {-1,0,1};
  int dy[3] = {1,1,1};
  if(mp[y][x] == 2) y+=2;
  
  if((y >= h)||(y==h-1 && mp[y][x] != 1)) ans++;//,cout <<"ok"<<endl;  
  else if(mp[y][x] != 1) {
    for(int i=0;i<3;i++) {
      int nx = dx[i]+x;
      int ny = dy[i]+y;
      if(nx <0||ny <0||nx >= w|| ny>=h) continue;
      if(mp[ny][nx] == 0){
      saiki(nx,ny);
      }
      else if(nx==x && mp[ny][nx] == 2 ){
	saiki(nx,ny+2);
      }
    } 
  }
}

int main() {

  while(1) {
    cin >> w >> h;
    if(w == 0 && h == 0) break;

    for(int i=0;i<h;i++) 
      for(int j=0;j<w;j++) 
	cin >> mp[i][j];
    /*
    for(int i=0;i<h;i++) {
      for(int j=0;j<w;j++) 
	cout << mp[i][j];
	  cout << endl;
    }
    */

    ans = 0;
    count = 0;
    for(int i=0;i<w;i++) {
      if(mp[0][i] !=1) saiki(i,0);
    }
    cout << ans << endl;
    //cout << count << endl;
  }

  return 0;
}