#include <iostream>
using namespace std;
int main()
{
    while(1)
    {
        int x,y,ans=0;
        int dp[17][17]={0};
        int course[15][15]={0};
        cin>>x>>y;if(!x)return 0;
        for(int j=0;j<y;++j){
            for(int i=0;i<x;++i){
            	cin>>course[i][j];
            	if(!course[i][0])dp[i][0]=1;
            }
        }
        for(int j=0;j<y-1;++j){
            for(int i=0;i<x;++i){
                if(!course[i][j]){
                    if(course[i][j+1]!=1)dp[i][j+1]+=dp[i][j];
                    if(i){
                        if(!course[i-1][j+1])dp[i-1][j+1]+=dp[i][j];
                    }
                    if(i<x){
                        if(!course[i+1][j+1])dp[i+1][j+1]+=dp[i][j];
                    }
                }
                if(course[i][j]==2){
                    if(course[i][j]!=1)dp[i][j+2]+=dp[i][j];
                }
            }
        }
        for(int j=y-1;j<y+2;++j){
            for(int i=0;i<x;++i){
                ans+=dp[i][j];
            }
        }
        cout<<ans<<endl;
    }
}