#include<iostream>
#include<algorithm>
using namespace std;
int main(){
   int x,y;
   while(cin>>x>>y,x||y){
        int field[50][50];
        for(int i=1;i<=y;i++)
            for(int j=1;j<=x;j++)
                cin>>field[i][j];

        int dp[50][50]={{0}};
        for(int i=1;i<=x;i++)dp[1][i]=1;
        for(int i=1;i<=y;i++){
            for(int j=1;j<=x;j++){
                if(field[i][j]==1){
                    dp[i][j]=0;
                    continue;
                }
                if(i==y)continue;
                if(field[i][j]==2){
                    int to=i+2;
                    dp[to][j]+=dp[i][j];
                    continue;
                }
                if(field[i+1][j+1]!=2)dp[i+1][j+1]+=dp[i][j];
                if(field[i+1][j-1]!=2)dp[i+1][j-1]+=dp[i][j];
                dp[i+1][j]+=dp[i][j];
            }
        }
        int sum=0;
        for(int i=1;i<=x;i++)sum+=dp[y][i]+dp[y+1][i];
        cout<<sum<<endl;

   }
}