#include <iostream>

using namespace std;

int X, Y, c[20][20], dp[20][20];
int dx[3] = {-1, 0, 1};

int main()
{
  while (cin >> X >> Y && (X && Y)) {
    
    for (int i = 1; i <= Y; i++)
      for (int j = 1; j <= X; j++)
        cin >> c[i][j];
    
    for (int x = 1; x <= X; x++) {
      dp[Y + 1][x] = dp[Y + 2][x] = 1;
      if (c[Y][x] == 1) {
        dp[Y][x] = 0;
      } else {
        dp[Y][x] = 1;
      }
    }
    
    for (int y = Y - 1; y >= 1; y--) {
      for (int x = 1; x <= X; x++) {
        dp[y][x] = 0;
        if (c[y][x] == 2) {
          dp[y][x] += dp[y + 2][x];
        } else if (c[y][x] == 0) {
          for (int k = 0; k < 3; k++) {
            int nx = x + dx[k];
            if (nx >= 1 && nx <= X) {
              if (nx != x) {
                if (c[y + 1][nx] == 0) {
                  dp[y][x] += dp[y + 1][nx];
                }
              } else {
                if (c[y + 1][nx] != 1) {
                  dp[y][x] += dp[y + 1][nx];
                }
              }
            }
          }
        }
      }
    }
    
    int res = 0;
    for (int x = 1; x <= X; x++) 
      res += dp[1][x];

    cout << res << endl;
  }
}