#include<iostream>
#include<cstring>
using namespace std;

int w,h;
int data[20][20]; //y,x
int memo[20][20]; //y,x

int solve(int y, int x){

  if(x < 0 || y < 0 || x == w || y == h) return 0;
  if(memo[y][x] > 0) return memo[y][x];
  if(data[y][x] == 1) return 0;
  if(data[y][x] == 0 && y == h-1) return 1;
  if(data[y][x] == 2 && (y == h-2 || y == h-1)) return 1;

  if(data[y][x] == 2) return memo[y][x] = solve(y+2,x);

  if(x > 0 && !data[y+1][x-1] && !data[y+1][x+1])
    return memo[y][x] = solve(y+1,x-1) + solve(y+1,x) + solve(y+1,x+1);

  else if(x > 0 && !data[y+1][x-1])
    return memo[y][x] = solve(y+1,x-1) + solve(y+1,x);

  else if(!data[y+1][x+1])
    return memo[y][x] = solve(y+1,x) + solve(y+1,x+1);

  else return memo[y][x] = solve(y+1,x);
}

int main(){

  while(true){
    cin >> w >> h;
    if(!w && !h) break;

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++) cin >> data[i][j]; //y,x
    }

    int ans = 0;
    for(int i=0;i<w;i++){
      memset(memo,0,sizeof(memo));
      ans += solve(0,i); //y,x
    }

    cout << ans << endl;
  }
}