#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)
const int N = 1000000;
map<pair<int, int>, vector<int> > mp;
vector<int> g[N + 1];
int n, m, fr[N + 1];
bool vis[N + 1];
vector<int> an;
bool is_main_node(int v){
return g[v].size() >= 2 && v;
}
void no(){
printf("-1\n");
exit(0);
}
pair<int, int> make_p(int a, int b){
if (a > b)swap(a, b);
return make_pair(a, b);
}
void fill_edge(int a, int b){
for (int t: mp[make_p(a, b)])an.push_back(t);
}
void go(int v){
vis[v] = true;
for (int u: g[v])if (!is_main_node(u)){
fill_edge(v, u);
vis[u] = true;
}
for (int u: g[v])if (is_main_node(u) && !vis[u]){
fill_edge(v, u);
return go(u);
}
}
int main() {
scanf("%d%d", &n, &m);
f(i, 1, n + 1){
int s, a, b = 0;
scanf("%d%d", &s, &a);
if (s == 2)scanf("%d", &b);
mp[make_p(a, b)].push_back(i);
g[a].push_back(b);
g[b].push_back(a);
}
f(i, 1, m + 1){
sort(g[i].begin(), g[i].end());
g[i].resize(unique(g[i].begin(), g[i].end()) - g[i].begin());
}
f(i, 1, m + 1)for (int u: g[i])if (is_main_node(u))++fr[i];
f(i, 1, m + 1)if (fr[i]> 2)no();
f(i, 1, m + 1)if (!vis[i] && is_main_node(i) && fr[i] <= 1)go(i);
f(i, 1, m + 1)if (!vis[i] && fr[i] == 0)go(i);
f(i, 1, m + 1)if (!vis[i])no();
f(i, 0, n)printf("%d%c", an[i], i + 1 < n ? ' ' : '\n');
}
Copy