#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int main(){

  int x,y;
  int a[100][100];
  int w[100][100];

  while(true){
    cin >> x >> y;
    if(!x && !y) break;

    memset(w,0,sizeof(w));
    int ans = 0;

    for(int i=0;i<y;i++){
      for(int j=0;j<x;j++) cin >> a[i][j];
    }

    for(int i=0;i<x;i++){
      if(a[0][i] == 0) w[0][i] = 1;
    }

    for(int i=1;i<y;i++){
      for(int j=0;j<x;j++){

	if(a[i][j] == 1) w[i][j] += 0;

	else if(a[i][j] == 2 && a[i+2][j] != 1) w[i+2][j] += w[i-1][j];

	else if(a[i][j] == 0){
	  if(i-3 > 0 && a[i-3][j+1] == 2 && a[i-3][j-1] == 2) w[i][j] += w[i-1][j];
	  else if(i-3 > 0 && a[i-3][j+1] == 2) w[i][j] += w[i-1][j-1] + w[i-1][j];
	  else if(i-3 > 0 && a[i-3][j-1] == 2) w[i][j] += w[i-1][j] + w[i-1][j+1];
	  else if(j-1 < 0) w[i][j] += w[i-1][j] + w[i-1][j+1];
	  else if(j+1 == y) w[i][j] += w[i-1][j-1] + w[i-1][j];
	  else w[i][j] += w[i-1][j-1] + w[i-1][j] + w[i-1][j+1];
	}


      }
    }

    for(int i=0;i<x;i++) ans += w[y-1][i] + w[y][i] + w[y+1][i];
    cout << ans << endl;
  }
}