#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e6 + 5;


int link[N], sz[N];

int find(int a) {
    return a == link[a]? a : link[a] = find(link[a]);
}

bool unite(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b) return false;
    if (sz[a] < sz[b]) swap(a, b);
    sz[a] += sz[b];
    link[b] =a ;
    return true;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    int n, m;
    cin >> n >> m;

    iota(link, link + N, 0);
    fill(sz, sz + N, 1);

    vector< int> ans;

    for (int i = 0; i < n; i++) {
        int a, b = m + 1, k;
        cin >> k;

        cin >> a;
        if (k > 1) cin >> b;
        if (unite(a, b)) ans.push_back(i + 1);
    }

    cout << size(ans) << "\n";
    for (int x : ans) cout << x << "\n";
}