#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int koi[10], tema, temi[11][21], maxx, pored, izcherpani[21], a;

int main ()
{
    
    int n, k, brk;
    
    cin >> n >> k;
    bool da = true;
    for (int i = 0; i < n; i ++)
    {
        cin >> brk;
        
        if (brk == k && da)
        {
            koi[a] = 1;
            a ++;
            da = false;
        }
        
        for (int j = 1; j <= brk; j ++)
        {
            cin >> tema;
            temi[i][tema] = true;
        }
        
        if (maxx < brk)
        {
            maxx = brk;
            pored = i;
        }
    }
    if (da){
    for (int i = 1; i <= k; i ++)
    {
        if (temi[pored][i])
        {
            izcherpani[i] = true;
        }
    }
    
    for (int i = n; i >= 0; i --)
    {
        if (i != pored)
        {
            for (int j = 1; j <= k; j ++)
            {
                if (temi[i][j] && (!izcherpani[j]))
                {
                    izcherpani[j] = true;
                    koi[a] = i;
                    a ++;
                }
            }
        } else
        {
            koi[a] = pored;
            a ++;
        }
    }
}
    if (da)
    {
    cout << a << endl;
    sort (koi + 0, koi + a);
    cout << koi[0] + 1;
    for (int i = 1; i < a; i ++)
    {
        cout << " " << koi[i] + 1;
    }
    
    cout << endl;
    }
    
    if (!da)
    {
        cout << 1 << endl << koi[0] << endl;
    }
    return 0;
}
