#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;

int  X,Y,dx[]={-1,0,1},dy[]={1,1,1};
long long ans;
int field[15][15];

void dfs(int x,int y){
    if(y >= Y-1){
        if(field[y][x]!=1){
            ans++;
            return;
        }
    }
    if(field[y][x] == 2){
        dfs(x,y+2);
        return ;
    }
    if(field[y][x] == 1){
        return ;
    }
    
    for(int i=0;i<3;i++){
        int nx = x+dx[i],ny = y+dy[i];
        if(nx>=0 && nx<X && ny>=0 && ny<Y && field[ny][nx] != 1 && !(i != 1 && field[ny][nx] == 2)){
            if(field[ny][nx] == 2)dfs(nx,ny+2);
            else dfs(nx,ny);
        }
    }
}

void solve(){
    for(int x=0;x<X;x++){
        if(field[0][x] == 0)dfs(x,0);
    }
}

int main() {
	while(1){
     memset(field,0,sizeof(field));
     ans=0;
     cin>>X>>Y;   
     if(!X&&!Y)break;
     
     for(int i=0;i<Y;i++){
         for(int j=0;j<X;j++){
             cin>>field[i][j];
         }
     }
     
     solve();
     
     cout<<ans<<endl;
	}
	return 0;
}