#include <iostream>
#include <vector>

using namespace std;

vector<int> bilancia(int N, int M, vector<vector<int>> S) {
    vector<int> ans(4);
    ans[1] = 9;
    for (int i = 0; i < N; ++i)
        for (int j = 0; j < S[i].size(); ++j)
            if (S[i][j] == 34)
                return { 6, 9 };
    if (N == 6)
        return ans;
    if (N == M)
        return { 0, 1, 2 };
    // Vettore vuoto
    return {};
}

// NON TOCCARE SOTTO QUESTA LINEA

#ifndef EVAL

int main() {
    int N, M;
    cin >> N >> M;

    vector<vector<int>> S(N);

    for (vector<int>& i : S) {
        int size;
        cin >> size;
        i.resize(size);
        for (int& j : i)
            cin >> j;
    }

    vector<int> ans = bilancia(N, M, S);

    if (ans.size() == 0)
        cout << "IMPOSSIBLE";
    for (int i : ans)
        cout << i << ' ';
    cout << endl;
}

#endif
