#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main(){
  int i,j,x,y,a[16][15],n[15][15],k,ans;
  while(1){
    cin >> x >> y;
    if(x == 0 && y == 0) break;
    for(i=0;i<y;i++){
      for(j=0;j<x;j++){
	cin >> n[i][j];
      }
    }

    for(j=0;j<x;j++){
      for(i=0;i<=y;i++) a[i][j] = 0;
      if(n[0][j] == 0) a[0][j] = 1;
    }

    for(i=0;i<y;i++){
      for(j=0;j<x;j++){
	if(n[i][j] == 1) continue;
	if(i == y-1) a[i+1][j] += a[i][j];
	else if(n[i][j] == 0){
	  for(k=-1;k<=1;k++){
	    if(j == 0 && k == -1 || j == x-1 && k == 1) continue;
	    if(n[i+1][j+k] == 0) a[i+1][j+k] += a[i][j];
	  }
	  if(n[i+1][j] == 2) a[i+1][j] += a[i][j];
	}
	else if(n[i][j] == 2){
	  if(n[i+2][j] != 1) a[i+2][j] += a[i][j];
	}
      }
    }

    ans = 0;
    for(j=0;j<x;j++) ans += a[y][j];
    cout << ans << endl;

  }
  return 0;
}