#include<iostream>
#include<string>

using namespace std;

int main(){
  int x, y, course[15][15], route[20][20], i, j, sum;
  while(cin >> x >> y, x+y){
    sum = 0;
    for(i=0; i<20; i++){
      for(j=0; j<20; j++){
        route[i][j] = 0;
      }
    }
    for(i=0; i<y; i++){
      for(j=0; j<x; j++){
        cin >> course[i][j];
      }
    }
    for(i=0; i<y; i++){
      for(j=0; j<x; j++){
        if(i==0){
          if(course[i][j]==0){
            route[i][j] = 1;
	  }else{
            route[i][j] = 0;
          }
        }else{
          if(j==0){
            if(course[i][j]==0){
              if(course[i-1][j]==0){
                route[i][j] += route[i-1][j];
              }
              if(course[i-1][j+1]==0){
                route[i][j] += route[i-1][j+1];
              }
            }else if(course[i][j]==1){
              route[i][j] = 0;
            }else{
              if(course[i-1][j]==0){
                route[i][j] += route[i-1][j];
              }
              route[i+2][j] += route[i][j];
            }
          }else if(j==x-1){
            if(course[i][j]==0){
              if(course[i-1][j]==0){
                route[i][j] += route[i-1][j];
              }
              if(course[i-1][j-1]==0){
                route[i][j] += route[i-1][j-1];
              }
            }else if(course[i][j]==1){
              route[i][j] = 0;
            }else{
              if(course[i-1][j]==0){
                route[i][j] += route[i-1][j];
              }
              route[i+2][j] += route[i][j];
            }
          }else{
            if(course[i][j]==0){
              if(course[i-1][j]==0){
                route[i][j] += route[i-1][j];
              }
              if(course[i-1][j-1]==0){
                route[i][j] += route[i-1][j-1];
              }
              if(course[i-1][j+1]==0){
                route[i][j] += route[i-1][j+1];
              }
            }else if(course[i][j]==1){
              route[i][j] = 0;
            }else{
              if(course[i-1][j]==0){
                route[i][j] += route[i-1][j];
              }
              route[i+2][j] += route[i][j];
            }
          }
        }
      }
    }
    for(i=y-1; i<y+1; i++){
      for(j=0; j<x; j++){
        sum+=route[i][j];
      }
    }
    cout << sum << endl;
  }
}