#include <iostream>
using namespace std;
int w,h;
int mp[20][20],memo[20][20];
int saiki(int x,int y){
  if(y >= h-1) return 1;
  for(int i=-1;i<=1;i++) {
    int nx = x+i, ny = y+1;
    if(nx==x && mp[ny][nx] == 2)while(mp[ny][nx] == 2) ny+=2;
    if(nx <0|| nx >= w ||mp[ny][nx] != 0) continue;
    if(memo[ny][nx]==0) memo[y][x]+=saiki(nx,ny);
    else memo[y][x] += memo[ny][nx];
  }
  mp[y][x] = 1;
  return memo[y][x];
}
int main() {
  while(1) {
    cin >> w >> h;
    if(w == 0 && h == 0) break;
    for(int i=0;i<=19;i++)
      for(int j=0;j<=19;j++)memo[i][j] = mp[i][j] = 0;
    
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)cin >> mp[i][j];
   
    int cnt = 0;  
    for(int i=0;i<w;i++)
      if(mp[0][i] !=1)cnt+=saiki(i,0);
    cout << cnt <<endl;
  }
  return 0;
}