#include <bits/stdc++.h>
using namespace std;

int main()
{
  int x, y;
  while (cin >> x >> y, x){
    int map[32][32];
    for (int i = 1; i <= y; i++){
      for (int j = 1; j <= x; j++){
        cin >> map[i][j];
      }
    }

    int dp[32][32] = {0};
    for (int j = 1; j <= x; j++) dp[1][j] = 1;
    for (int i = 1; i <= y; i++){
      for (int j = 1; j <= x; j++){
        if (map[i][j] == 1) continue;
        if (map[i][j] == 2){
          dp[i + 2][j] = dp[i][j];
          continue;
        }

        for (int k = -1; k < 2; k++){
          if (map[i + 1][j + k] == 2 && k) continue;
          dp[i + 1][j + k] += dp[i][j];
        }
      }
    }

    int ans = 0;
    for (int j = 1; j <= x; j++){
      ans += dp[y][j];
    }

    cout << ans << endl;
  }
}