#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)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