#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
int course[16][17][2];
int main()
{
  for(;;){
    int H,W;
    cin >> W >> H;
    if(H==0||W==0) break;
    memset(course,0,sizeof(course));
    for(int h=1; h<=H; h++){
      for(int w=1; w<=W; w++){
        cin >> course[h][w][0];
      }
    }
    for(int w=1; w<=W; w++){
      if(course[1][w][0] == 1) course[1][w][1] = 0;
      else course[1][w][1] = 1;
    }
    for(int h=2; h<=H; h++){
      for(int w=1; w<=W; w++){
        if(course[h][w][0] == 1){
          course[h][w][1] = 0;
        }else if(course[h][w][0] == 2){
          course[h][w][1] = course[h-1][w][1];
          if(course[h-2][w][0] == 2){
            course[h][w][1] += course[h-2][w][1];
          }
        }else {
          for(int i=-1; i<=1; i++){
            if(course[h-1][w+i][0] != 2){
              course[h][w][1] += course[h-1][w+i][1];
            }
          }
          if(course[h-2][w][0] == 2){
            course[h][w][1] += course[h-2][w][1];
          }
        }
      }
    }
    long long sum = 0;
    for(int w=1; w<=W; w++){
      sum += course[H][w][1];
      if(course[H-1][w][0] == 2){
        sum += course[H-1][w][1];
      }
    }
    cout << sum << endl;
  }
  return 0;
}