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

int main(){
  int W, H, mas[16][16];
  while( cin >> W >> H, W){
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        cin >> mas[i][j];
      }
    }
    vector< vector< int > > dp( H + 1, vector< int >(W, 0));
    for(int i = 0; i < W; i++){
      if(mas[0][i] != 1) dp[0][i] = 1;
    }
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        if(dp[i][j] == 0) continue;
        if(mas[i][j] == 0){
          for(int k = -1; k <= 1; k++){
            if(j + k < 0 || j + k >= W) continue;
            if((i == H - 1 && k == 0) || (k == 0 && mas[i + 1][j + k] == 2) || (i != H - 1 && mas[i + 1][j + k] == 0)){
              dp[i + 1][j + k] += dp[i][j];
            }
          }
        } else if(mas[i][j] == 2){
          if(i >= H - 2 || mas[i + 2][j] != 1){
            dp[max(H, i + 2)][j] += dp[i][j];
          }
        }
      }
    }

    int ret = 0;
    for(int i = 0; i < W; i++){
      ret += dp[H][i];
    }
    cout << ret << endl;
  }
}