// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {1, 1, 1};
int dy[] = {-1, 0, 1};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int board[20][20], dp[30][30];
 
signed main() {
    int W, H;
    while(cin >> W >> H, W || H) {
        for(int i=0; i<H; i++) {
            for(int j=0; j<W; j++) {
                cin >> board[i][j];
            }
        }

        memset(dp, 0, sizeof(dp));
        for(int i=0; i<W; i++) if(board[0][i] == 0) dp[0][i] = 1;

        int ans = 0;
        for(int i=0; i<H; i++) {
            for(int j=0; j<W; j++) {
                for(int k=0; k<3; k++) {
                    if(board[i][j] == 2 and k != 1) continue;
                    int dbl = (board[i][j] == 2 ? 2 : 1);

                    int ni = i + dx[k] * dbl, nj = j + dy[k];
                    if(ni < 0 or nj < 0 or nj >= W) continue;
                    if(board[ni][nj] == 1) continue;
                    if(board[ni][nj] == 2 and k != 1) continue;

                    if(ni < H - 1) {
                        dp[ni][nj] += dp[i][j];
                    }
                    else {
                        ans += dp[i][j];
                    }
                }
            }
        }

        cout << ans << endl;
    }
    return 0;
}
