Source Code
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define F first
#define S second
#define all(a) a.begin(),a.end()

using namespace std;

const ll Mod=1e9+7 ;

ll poww(ll a,ll b,ll mod){
    ll res=1;if(b<0)b=(b%(mod-1)+mod-1)%(mod-1);
    for(;b;b>>=1,a=1ll*a*a%mod)
      if(b&1)res=1ll*res*a%mod;
    return res;
}

void Max(ll& x,ll y){
x=max(x,y);
}
void Min(ll& x,ll y){
x=min(x,y);
}
void OK(bool yes){
    cout<<(yes?"Yes\n":"No\n");
}

const ll N=500500,M=2010,LN=(1<<24),K=17,Mx=4e6+50,inf=3e18,Mod1=1e9+7,Mod2=999997457;
const ld pi=acos(-1),eps=1e-12;

ll Fact[N];
void init(){
Fact[0]=1ll;
for(int i=1;i<N;i++)Fact[i]=(1ll*Fact[i-1]*i)%Mod;
}
int Cnk(ll x,ll y){
if(y > x)return 0;
return (  ((Fact[x]*poww(Fact[y],-1,Mod))%Mod)  *poww(Fact[x-y],-1,Mod))%Mod;
}


void Add(ll& x,ll y,int j=0){
ll mod=Mod;
if(j==1)mod=Mod1;
if(j==2)mod=Mod2;
x%=mod;
y%=mod;
if(x<0)x+=mod;
if(y<0)y+=mod;
x=(x+y>=mod?x+y-mod:x+y);
}
/*
void init(){
Fact[0]=iFact[0]=1ll;
for(int i=1;i<N;i++)Fact[i]=(Fact[i-1]*i)%Mod;
for(int i=1;i<N;i++)iFact[i]=(iFact[i-1]*poww(i,-1,Mod))%Mod;
}
*/

bool ok=1;

ll vis[N];

vector<ll> v1[N],Ans;
vector<pll> v[N];
map<pll,vector<ll>> pos;

void dfs(ll x){
if(vis[x])return;
vis[x]=1;
for(auto p:v1[x])Ans.pb(p);
if(v[x].size()<=2){
    for(auto p:v[x]){
        if(vis[p.F])continue;
        ll X=min(p.F,x);
        ll Y=max(p.F,x);
        for(auto pp:pos[{X,Y}]){
            Ans.pb(pp);
        }
        dfs(p.F);
    }
}
else{
    ll cnt=0,cnt2=0;
    for(auto p:v[x]){
        if(vis[p.F])continue;
        if(v[p.F].size()>1)cnt++;
        if(!v1[p.F].empty())cnt2++;
        if(cnt>1||cnt2>1)break;
    }
    if(cnt>1||cnt2>1){
        ok=0;
        return;
    }
    if(cnt==0){
        ll later=0,later_Ans=0;
        for(auto p:v[x]){
            if(vis[p.F])continue;
            if(!v1[p.F].empty()){
                later=p.F;
                later_Ans=p.S;
            }
            else{
                ll X=min(p.F,x);
                ll Y=max(p.F,x);
                for(auto pp:pos[{X,Y}]){
                    Ans.pb(pp);
                }
                dfs(p.F);
            }
        }
        if(later){
            ll X=min(later,x);
            ll Y=max(later,x);
            for(auto pp:pos[{X,Y}]){
                Ans.pb(pp);
            }
            dfs(later);
        }
    }
    else{

        ll later=0,later_Ans=0;
        for(auto p:v[x]){
            if(vis[p.F])continue;
            if(v[p.F].size()>1){
                later=p.F;
                later_Ans=p.S;
            }
            else{
                ll X=min(p.F,x);
                ll Y=max(p.F,x);
                for(auto pp:pos[{X,Y}]){
                    Ans.pb(pp);
                }
                if(!v1[p.F].empty())ok=0;
                dfs(p.F);
            }
        }
        if(later){
            ll X=min(later,x);
            ll Y=max(later,x);
            for(auto pp:pos[{X,Y}]){
                Ans.pb(pp);
            }
            dfs(later);
        }
    }
}

}


int main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);
    //cout.tie(0);

    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

    //freopen("heinto.in","r",stdin);


    int T=1;
    int Case=1;
    //init();
    //cin>>T;
    while(T--){
        ll n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++){
            ll k;
            cin>>k;
            if(k==1){
                ll x;
                cin>>x;
                v1[x].pb(i);
            }
            else{
                ll x,y;
                cin>>x>>y;
                if(x>y)swap(x,y);
                if(!pos[{x,y}].empty()){
                    pos[{x,y}].pb(i);
                    //ok=0;
                }
                else{
                    pos[{x,y}].pb(i);
                    v[x].pb({y,i});
                    v[y].pb({x,i});
                }
            }
        }
        for(int i=1;i<=m;i++){
            if(vis[i])continue;
            if(v[i].size()<=1&&(!v1[i].empty())){
                dfs(i);
            }
        }
        for(int i=1;i<=m;i++){
            if(vis[i])continue;
            if(v[i].size()<=1){
                dfs(i);
            }
        }
        if(Ans.size()!=n)ok=0;
        if(ok){
            for(auto p:Ans)cout<<p<<' ';
            cout<<'\n';
        }
        else{
            cout<<-1<<'\n';
        }
        //OK(ok);
    }

    return 0;
}
/*

6 7
2 1 2
2 2 7
2 4 7
2 5 4
2 5 6
2 3 7

3 3
2 1 2
2 1 2
2 1 3

10 5
2 5 1
2 5 2
2 5 3
2 5 4
1 1
1 2
1 2
2 5 3
2 5 4
1 4

7 4
2 1 2
2 2 3
2 2 4
1 3
1 4
1 3
1 4

10 10
2 1 2
2 2 3
2 2 4
2 4 5
2 4 6
2 6 7
2 6 8



*/

Copy
Gym Wise-ard
GNU G++17
16 ms
24.1 MB
Wrong Answer
Test Case #1
14 ms
23.9 MB
Accepted
Input
3 3
2 2 3
1 1
2 2 1
Output
2 3 1
Judge Output
2 3 1
Checker Message
ok
Test Case #2
14 ms
23.8 MB
Accepted
Input
4 10
1 4
1 9
1 4
1 9
Output
1 3 2 4
Judge Output
1 3 2 4
Checker Message
ok
Test Case #3
15 ms
24.1 MB
Accepted
Input
3 3
2 1 2
2 2 3
2 3 1
Output
-1
Judge Output
-1
Checker Message
ok
Test Case #4
13 ms
23.9 MB
Accepted
Input
1 1
1 1
Output
1
Judge Output
1
Checker Message
ok
Test Case #5
14 ms
24.1 MB
Accepted
Input
20 15
2 2 13
2 3 13
2 7 14
2 8 14
2 8 14
2 13 3
1 3
2 10 3
1 15
2 14 15
2 3 12
2 15 11
2 14 12
2 12 14
2 13 2
2 14 15
2 15 14
1 13
2 12 3
2 12 3
Output
1 15 18 2 6 7 8 11 19 20 13 14 3 4 5 10 16 17 9 12
Judge Output
18 1 15 2 6 7 8 11 19 20 13 14 3 4 5 10 16 17 9 12
Checker Message
ok
Test Case #6
13 ms
24.0 MB
Accepted
Input
40 30
2 11 14
2 2 5
1 20
2 27 18
2 20 11
1 17
1 19
2 26 3
1 30
2 27 7
2 4 13
2 4 17
2 15 17
2 11 8
1 27
2 3 26
2 10 27
2 20 7
2 11 24
2 7 27
2 17 2
2 7 20
2 27 18
2 27 10
2 2 28
2 30 11
2 11 20
2 13 4
2 3 26
1 20
2 6 17
2 11 20
2 7 27
2 27 18
2 26 4...
Output
7 9 40 26 1 14 19 5 27 32 3 30 18 22 39 10 20 33 15 4 23 34 17 24 36 8 16 29 35 11 28 12 37 6 13 31 21 2 25 38
Judge Output
2 25 38 21 6 31 13 12 37 11 28 35 8 16 29 36 17 24 15 4 23 34 10 20 33 39 18 22 3 30 5 27 32 14 1 19 26 9 40 7
Checker Message
ok
Test Case #7
14 ms
24.0 MB
Accepted
Input
80 60
1 46
2 52 43
2 16 19
2 25 1
1 2
2 3 17
2 57 38
2 53 59
2 43 47
2 26 21
2 14 51
2 12 35
2 52 43
2 14 51
2 5 9
2 9 44
2 15 44
2 38 26
2 51 2
2 44 15
2 54 28
2 44 34
2 46 58
2 3 17
2 54 28
2 11 43
2 11 43
2 12 18
2 54 28
2 38 27
2 12 16
1 12
2 51...
Output
42 62 4 67 74 15 16 22 54 17 20 35 64 49 58 43 56 1 57 72 23 65 59 52 79 11 14 33 36 53 19 38 5 68 47 48 69 40 21 25 29 45 66 3 31 32 55 78 12 61 73 80 41 70 28 44 63 60 7 30 50 18 10 39 76 34 75 77 2 13 9 26 27 46 6 24 37 8 51 71
Judge Output
42 62 4 67 74 15 16 22 54 17 20 35 64 49 58 43 56 1 57 72 65 23 59 52 79 11 14 33 36 53 19 38 5 68 47 48 69 40 21 25 29 45 66 3 31 32 55 78 41 70 12 61 73 80 28 44 63 60 30 50 7 18 10 39 76 34 75 77 2 13 26 27 9 6 24 37 46 8 51 71
Checker Message
ok
Test Case #8
16 ms
24.1 MB
Wrong Answer
Input
160 150
2 12 103
2 92 89
2 73 137
2 43 70
2 86 45
2 75 62
1 49
2 83 19
2 93 125
1 60
1 101
2 59 35
2 142 76
2 114 17
2 92 89
2 128 130
2 97 11
2 122 60
2 103 58
2 121 106
2 26 83
1 73
1 110
2 79 101
1 61
2 49 21
2 63 81
1 11
2 61 148
2 92 24
2 49 55...
Output
-1
Judge Output
56 117 1 83 137 62 19 119 120 158 87 54 147 12 150 132 10 38 39 80 153 18 25 115 29 151 35 46 127 61 27 94 22 47 49 130 89 126 3 102 108 16 82 70 78 159 9 34 71 143 81 40 139 28 157 45 73 17 53 105 68 59 75 104 131 96 123 74 98 140 4 86 93 23 76 100...
Checker Message
participant coudln't find answer but jury did