
#include <iostream>
#include <cstdio>

using namespace std;

int field[20][20];
long long dp[20][20];

int main()
{
  int c1, c2;
  while (scanf(" %d %d ", &c1, &c2) == 2) {
    if (c1 == 0 && c2 == 0) {break;}
    for (int i = 0; i < 20; i++) {
      fill(field[i], &field[i][20], 1);
      fill(dp[i], &dp[i][20], 0);
    }
    for (int i = 1; i <= c1; i++) {
      for (int j = 1; j <= c2; j++) {
	scanf(" %d ", &field[i][j]);
      }
    }
    /*for (int i = 0; i < 20; i++) {
      for (int j = 0; j < 20; j++) {
	printf("%d", field[i][j]);
      }
      printf("\n");
      }*/
    
    for (int i = 1; i <= c2; i++) {
      dp[1][i] = 1;
    }
    for (int i = 1; i < c1; i++) {
      for (int j = 1; j <= c2; j++) {
	if (field[i][j] == 0) {
	  if (field[i + 1][j - 1] != 2) {dp[i + 1][j - 1] += dp[i][j];}
	  dp[i + 1][j] += dp[i][j];
	  if (field[i + 1][j + 1] != 2) {dp[i + 1][j + 1] += dp[i][j];}
	} else if (field[i][j] == 2) {
	  dp[i + 2][j] += dp[i][j];
	} 
      }
    }
    long long sum = 0;
    for (int i = 0; i <= 2; i++) {
      for (int j = 1; j <= c2; j++) {
	if ((i != 0 || field[c1 + i][j] != 1) && (i != 0 || field[c1 + i][j] != 2)) {
	  sum += dp[c1 + i][j];
	}
      }
    }
    
    printf("%d\n", sum);
  }
}