#include <stdio.h>
const int X=20;
const int Y=20;
int main(){
    int n,m,dp[X][Y],s[X][Y],k,ans;
    while(true){
        scanf("%d%d",&n,&m);
        if(n==0&&m==0)return 0;
        ans=0;
        for(int i=0;i<n+2;i++)for(int j=0;j<m;j++)dp[i][j]=s[i][j]=0;
        for(int i=0;i<m;i++)dp[0][i]=1;
        for(int i=0;i<n;i++)for(int j=0;j<m;j++){
            scanf("%d",&k);
            if(k==0){
                dp[i][j]+=s[i][j];
                if(i==n-1)continue;
                dp[i+1][j]+=dp[i][j];
                if(j!=0)s[i+1][j-1]+=dp[i][j];
                if(j!=n-1)s[i+1][j+1]+=dp[i][j];
            }
            else if(k==2){
                s[i][j]=0;
                if(i==n-1)continue;
                dp[i+2][j]+=dp[i][j];
            }
            else dp[i][j]=s[i][j]=0;
        }
        for(int i=0;i<m;i++)ans+=dp[n][i]+dp[n-1][i];
        
        printf("%d\n",ans);
    }
}
