#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(void){
  int x,y;
  int m[20][20];
  for( ; ; ){
    cin >> x >> y;
    if(!x && !y) break;

    memset(m,0,sizeof(m));

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

    long long dp[20][20] = {0};
    long long ans = 0;

    for(int i = 0;i < y; i++){
      for(int j = 0;j < x; j++){
	if(i == 0){
	  if(m[i][j] == 0) dp[i][j] = 1;
	}
	if(m[i][j] == 2 && m[i+2][j] != 1) dp[i+2][j] += dp[i][j];
	else if(!m[i][j] && !j){
	  dp[i+1][j] += dp[i][j];
	  if(!m[i+1][j+1]) dp[i+1][j+1] += dp[i][j];
	}
	else if(!m[i][j] && j == x-1){
	  dp[i+1][j] += dp[i][j];
	  if(!m[i+1][j-1]) dp[i+1][j-1] += dp[i][j];
	}
	else if(!m[i][j]){
	  if(!m[i+1][j-1]) dp[i+1][j-1] += dp[i][j];
	  dp[i+1][j] += dp[i][j];
	  if(!m[i+1][j+1]) dp[i+1][j+1] += dp[i][j];
	}
      }
    }

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

    cout << ans << endl;
  }
}
