#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
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(i-2 >= 0 && a[i-2][j] == 2) w[i][j] += w[i-2][j];

	if(j-1 >= 0 && !a[i-1][j-1] && !a[i][j]) w[i][j] += w[i-1][j-1];
	if(j+1 < x && !a[i-1][j+1] && !a[i][j]) w[i][j] += w[i-1][j+1];

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

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

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

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

    cout << ans << endl;
  }
}