#include <bits/stdc++.h>   using namespace std;   long long read() {     long long cc = getc(stdin);     for (; cc <  0  || cc >  9 ;) cc = getc(stdin);     long long ret = 0;     for (; cc >=  0  && cc <=  9 ;) {       ret = ret * 10 + cc -  0 ;       cc = getc(stdin);     }     return ret;   }   long long power(long long num, long long g) {     if (g == 0) return 1;     if (g % 2 == 1)       return (num * power((num * num) % 998244353, g / 2)) % 998244353;     return power((num * num) % 998244353, g / 2);   }   int parent[100005];   int siz[100005];   int find(int index) {     if (parent[index] == index) return index;     return parent[index] = find(parent[index]);   }   vector<pair<int, int> > vec[100005];   int b[100005][18], c[100005][18];   int timer, intime[100005], outtime[100005], level[100005];   void dfs(int index, int par, int lev) {     level[index] = lev;     timer++;     intime[index] = timer;     parent[index] = par;     for (long long i = 0; i < vec[index].size(); i++) {       if (vec[index][i].first == par) continue;       c[vec[index][i].first][0] = vec[index][i].second;       dfs(vec[index][i].first, index, lev + 1);     }     timer++;     outtime[index] = timer;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     pair<pair<int, int>, pair<int, int> > pa[m];     vector<pair<int, int> > vec1;     for (long long i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       pa[i] = make_pair(make_pair(w, i), make_pair(u, v));     }     sort(pa, pa + m);     for (long long i = 0; i < n; i++) parent[i + 1] = i + 1, siz[i + 1] = 1;     for (long long i = 0; i < m; i++) {       int u = pa[i].second.first;       int v = pa[i].second.second;       int w = pa[i].first.first;       int g = find(u);       int h = find(v);       if (g == h) continue;       if (siz[g] > siz[h])         siz[g] += siz[h], parent[h] = g;       else         siz[h] += siz[g], parent[g] = h;       vec[u].push_back(make_pair(v, w));       vec[v].push_back(make_pair(u, w));     }     timer = 0;     dfs(1, 1, 1);     for (long long i = 0; i < n; i++) {       b[i + 1][0] = parent[i + 1];     }     for (int i = 1; i <= 17; i++) {       for (int j = 1; j <= n; j++) {         b[j][i] = b[b[j][i - 1]][i - 1];         c[j][i] = max(c[j][i - 1], c[b[j][i - 1]][i - 1]);       }     }     for (long long i = 0; i < n; i++) parent[i + 1] = i + 1, siz[i + 1] = 1;     for (long long i = 0; i < m; i++) {       int u = pa[i].second.first;       int v = pa[i].second.second;       int w = pa[i].first.first;       int xyz = pa[i].first.second;       int g = find(u);       int h = find(v);       if (g == h) {         int g = 1 << 17;         int ans = 0;         int h = u;         for (int j = 17; j >= 0; j--) {           int d = b[h][j];           if (intime[d] <= intime[v] && outtime[d] >= outtime[v]) {             continue;           }           ans = max(ans, c[h][j]);           h = d;         }         while (intime[h] > intime[v] || outtime[h] < outtime[v]) {           ans = max(ans, c[h][0]);           h = b[h][0];         }         h = v;         for (int j = 17; j >= 0; j--) {           int d = b[h][j];           if (intime[d] <= intime[u] && outtime[d] >= outtime[u]) {             continue;           }           ans = max(ans, c[h][j]);           h = d;         }         while (intime[h] > intime[u] || outtime[h] < outtime[u]) {           ans = max(ans, c[h][0]);           h = b[h][0];         }         vec1.push_back(make_pair(xyz, ans));         continue;       }       if (siz[g] > siz[h])         siz[g] += siz[h], parent[h] = g;       else         siz[h] += siz[g], parent[g] = h;       vec[u].push_back(make_pair(v, w));       vec[v].push_back(make_pair(u, w));     }     sort(vec1.begin(), vec1.end());     for (long long i = 0; i < vec1.size(); i++) cout << vec1[i].second << endl;     return 0;   }