#include <iostream>
using namespace std;

int X, Y;
int a[15][15];
int b[16][15];

bool input() {
  cin >> X >> Y;
  if (!X && !Y) {
    return false;
  }
  for (int y = 0; y < Y; ++y) {
    for (int x = 0; x < X; ++x) {
      cin >> a[y][x];
    }
  }
  return true;
}

void solve() {
  for (int y = 0; y <= Y; ++y) {
    for (int x = 0; x < X; ++x) {
      b[y][x] = 0;
    }
  }
  for (int x = 0; x < X; ++x) {
    if (a[0][x] != 1) {
      b[0][x] = 1;
    }
  }

  for (int y = 0; y < Y - 1; ++y) {
    for (int x = 0; x < X; ++x) {
      if (!a[y][x]) {
        for (int dx = -1; dx <= 1; ++dx) {
          int nx = x + dx;
          if (nx >= 0 && nx < X && !a[y + 1][nx]) {
            b[y + 1][nx] += b[y][x];
          }
        }
        if (a[y + 1][x] == 2) {
          b[y + 1][x] += b[y][x];
        }
      } else if (a[y][x] == 2) {
        if (a[y + 2][x] != 1) {
          b[y + 2][x] += b[y][x];
        }
      }
    }
  }

  int ans = 0;
  for (int y = Y - 1; y <= Y; ++y) {
    for (int x = 0; x < X; ++x) {
      ans += b[y][x];
    }
  }
  cout << ans << endl;
}

int main() {
  while (input()) {
    solve();
  }
}