#include "bits/stdc++.h"

using namespace std;

typedef pair<int,int> pii;
typedef vector<int> vi;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

int main(){
    int w,h;
    while(cin>>w>>h){
        if(w==0&&h==0)break;
        int data[20][20];
        rep(i,h){
            rep(j,w){
                cin>>data[i][j];
            }
        }
        int dp[20][20];
        rep(i,20)rep(j,20)dp[i][j]=0;
        rep(i,w){
            if(data[0][i]==0){
                dp[0][i]=1;
            }
        }
        
        for(int i=0;i<h-1;i++){
            for(int j=0;j<w;j++){
                if(j-1>=0 && data[i+1][j-1]==0)dp[i+1][j-1]+=dp[i][j];
                if(data[i+1][j]==0)dp[i+1][j]+=dp[i][j];
                if(data[i+1][j]==2){
                    int c=1;
                    while(data[i+1+2*c][j]==2)c++;
                    dp[min(h-1,i+1+c*2)][j]+=dp[i][j];
                }
                if(j+1<w && data[i+1][j+1]==0)dp[i+1][j+1]+=dp[i][j];
            }
        }
        int ans=0;
        rep(i,w){
            ans+=dp[h-1][i];
        }
        cout<<ans<<endl;
    }
}