#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int w, h;
        cin >> w >> h;
        if(w == 0)
            return 0;

        vector<vector<int> > grid(h+1, vector<int>(w+2, 0));
        for(int i=0; i<h+1; ++i)
            grid[i][0] = grid[i][w+1] = 1;
        for(int i=0; i<h; ++i){
            for(int j=1; j<=w; ++j){
                cin >> grid[i][j];
            }
        }

        vector<vector<int> > num(h+1, vector<int>(w+2, 0));
        for(int i=1; i<=w; ++i){
            if(grid[0][i] == 0)
                num[0][i] = 1;
        }

        for(int y=0; y<h-1; ++y){
            for(int x=1; x<=w; ++x){
                if(grid[y][x] == 2){
                    num[y+2][x] += num[y][x];
                }else{
                    for(int dx=-1; dx<=1; ++dx){
                        if(grid[y+1][x+dx] == 1 || (grid[y+1][x+dx] == 2 && dx != 0))
                            continue;
                        num[y+1][x+dx] += num[y][x];
                    }
                }
            }
        }

        int ret = accumulate(num[h-1].begin(), num[h-1].end(), 0);
        ret += accumulate(num[h].begin(), num[h].end(), 0);
        cout << ret << endl;
    }
}