#include <iostream>
#include <cstring>
using namespace std;

const int MAX = 15;
const int dx[] = {-1, 0, 1};
int X, Y;
int c[MAX + 2][MAX + 2], dp[MAX + 2][MAX + 2];

int main()
{
    while(cin >> X >> Y && X) {
        for(int i = 1; i <= Y; i++)
            for(int j = 1; j <= X; j++)
                cin >> c[i][j];

        memset(dp, 0, sizeof(dp));
        for(int j = 1; j <= X; j++) 
            dp[1][j] = (c[1][j] == 0) ? 1 : 0;
        
        for(int i = 2; i <= Y; i++) {
            for(int j = 1; j <= X; j++) {
                if(c[i][j] == 0) {
                    for(int k = 0; k < 3; k++)
                        if(c[i - 1][j + dx[k]] == 0)
                            dp[i][j] += dp[i - 1][j + dx[k]];
                } else if(c[i][j] == 1) {
                    dp[i][j] = 0;
                } else {
                    if(dp[i][j] == 0) 
                        dp[i][j] = dp[i - 1][j];
                    dp[i + 2][j] = dp[i][j];
                }
            }
        }
        
        int ans = 0;
        for(int j = 1; j <= X; j++) 
            if(dp[Y + 1][j] > 0)
                ans += dp[Y + 1][j];
            else 
                ans += dp[Y][j];

        cout << ans << endl;
        
    }
}