#include<iostream>
#include<cstring>
#define INF 1<<20
using namespace std;

int w, h;
int data[22][22];
int memo[22][22];

int solve(int x, int y){

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

  int ret = 0;
  if(data[y][x] == 2) ret += solve(x, y+2);
  else{
    if(!data[y+1][x-1]) ret += solve(x-1, y+1);
    if(!data[y+1][x+1]) ret += solve(x+1, y+1);
    ret += solve(x, y+1);
  }
  
  return memo[y][x] = ret;
}

int main(){

  while(cin >> w >> h, w+h){

    for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin >> data[i][j];

    memset(memo, 0, sizeof(memo));
    int ans = 0;
    for(int i=0;i<w;i++) ans += solve(i, 0);

    cout << ans << endl;
  }

}