#include <iostream>
#include <vector>

using namespace std;

const int MOD = 998244353;

int main(){
    int K, N;
    while(cin >> K >> N){
        vector<vector<long long>> pair(K+1, vector<long long>(N+1, 0));
        vector<vector<long long>> solo(K+1, vector<long long>(N+1, 0));
        pair[0][0] = 1;
        solo[0][0] = 1;
        for(int i=1;i<=K;i++){
            long long sum = 0;
            for(int j=0;j<=N;j++){
                pair[i][j] += pair[i-1][j] + 2 * sum;
                pair[i][j] %= MOD;
                sum += pair[i-1][j];
                sum %= MOD;
            }
        }
        for(int i=1;i<=K;i++){
            long long sum = 0;
            for(int j=0;j<=N;j++){
                sum += solo[i-1][j];
                sum %= MOD;
                solo[i][j] = sum;
            }
        }
        vector<int> invalid(2*K+1, 0);
        for(int i=1;i<=K;i++){
            for(int j=i+1;j<=K;j++){
                ++invalid[i+j];
            }
        }
        for(int k=2;k<=2*K;k++){
            long long res = 0;
            int pr = invalid[k];
            if(k%2 == 0){
                for(int i=0;i<=N;i++){
                    res += pair[pr][i] * (solo[K-2*pr-1][N-i] + (i==N ? 0 : solo[K-2*pr-1][N-i-1]));
                    res %= MOD;
                }
            } else {
                for(int i=0;i<=N;i++){
                    res += pair[pr][i] * solo[K-2*pr][N-i];
                    res %= MOD;
                }
            }
            cout << res << endl;
        }
    }
}
#include <algorithm>
#include <iostream>
#include <queue>

using namespace std;

typedef pair<int, int> P;
const int inf = 1 << 28;

int w, h;
int a[21][21];
int sx, sy, gx, gy;

const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

bool check(int x, int w) { return 0 <= x && x < w; }

int dfs(int x, int y, int cnt) {
    if (cnt >= 10) {
        return inf;
    }

    int ret = inf;

    for (int k = 0; k < 4; ++k) {
        int nx = x + dx[k], ny = y + dy[k];

        while (check(nx, w) && check(ny, h) && a[ny][nx] != 1 &&
               a[ny][nx] != 3) {
            nx += dx[k];
            ny += dy[k];
        }

        if (!check(nx, w) || !check(ny, h)) {
            continue;
        }

        if (a[ny][nx] == 3) {
            return 1;
        }

        if (nx - dx[k] == x && ny - dy[k] == y) {
            continue;
        }

        a[ny][nx] = 0;

        ret = min(ret, dfs(nx - dx[k], ny - dy[k], cnt + 1) + 1);

        a[ny][nx] = 1;
    }

    return ret;
}

int main() {
    while (cin >> w >> h, !(w == 0 && h == 0)) {
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                cin >> a[i][j];

                if (a[i][j] == 2) {
                    sy = i;
                    sx = j;
                }

                if (a[i][j] == 3) {
                    gy = i;
                    gx = j;
                }
            }
        }

        int ans = dfs(sx, sy, 0);

        if (ans <= 10) {
            cout << ans << endl;
        } else {
            cout << -1 << endl;
        }
    }
}