#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
 
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;
int main(){
    int w,h;
    while(scanf("%d%d",&w,&h),w|h){
        int stage[32][32]={{0}};
        int    dp[32][32]={{0}};
        rep(i,h)rep(j,w)scanf("%d",&stage[i+1][j+1]);

        reps(i,1,w+1)if(stage[1][i] == 0)dp[1][i] = 1;

        reps(i,2,h+1){
            reps(j,1,w+1){
                if(stage[i][j] == 2){
                    dp[i+2][j] += dp[i-1][j] + dp[i][j];
                    dp[i][j] = 0;
                }
                else if(stage[i][j] == 1){
                    dp[i][j] = 0;
                }
                else if(stage[i][j] == 0){
                    dp[i][j] += dp[i-1][j-1] + dp[i-1][j] + dp[i-1][j+1];
                }
            }
        }

        int ans = 0;
        rep(i,w+1){
            ans += dp[h][i] + dp[h+1][i] + dp[h+2][i];
        }
        printf("%d\n",ans);
    }
    return 0;
}