#include<bits/stdc++.h> #define re register #define int long long
usingnamespace std;
constint N = 2e5 + 10,M = 4e5 + 10; int n,m; int f[N],val[N]; vector<int> v;
inlineintread(){ int r = 0,w = 1; char c = getchar(); while (c < '0' || c > '9'){ if (c == '-') w = -1; c = getchar(); } while (c >= '0' && c <= '9'){ r = (r << 3) + (r << 1) + (c ^ 48); c = getchar(); } return r * w; }
inlineintfind(int x){ if (f[x] != x){ int pf = f[x]; f[x] = find(f[x]); val[x] += val[pf]; } return f[x]; }
signedmain(){ n = read(); m = read(); for (re int i = 1;i <= n;i++) f[i] = i; for (re int i = 1;i <= m;i++){ int a,b,c; a = read(); b = read(); c = read(); if (merge(a,b,c)) v.push_back(i); } for (auto u:v) printf("%lld ",u); return0; }