#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
const int MAXM = 1000005;
const int MAXLOGN = 18;
int N, M;
tuple<int, int, int, int> E[MAXM];
int par[MAXN];
vector<pair<int, int> > adj[MAXN];
int jmp[MAXN][MAXLOGN];
int len[MAXN][MAXLOGN];
int dep[MAXN];
bool bad[MAXM];
int ans[MAXM];
void process() {
  for (int j = 1; j < MAXLOGN; j++)
    for (int i = 0; i < N; i++) {
      jmp[i][j] = jmp[jmp[i][j - 1]][j - 1];
      len[i][j] = max(len[i][j - 1], len[jmp[i][j - 1]][j - 1]);
    }
}
int query(int a, int b) {
  if (dep[a] > dep[b]) swap(a, b);
  int best = 0;
  for (int i = MAXLOGN - 1; i >= 0; i--)
    if (dep[jmp[b][i]] >= dep[a]) {
      best = max(best, len[b][i]);
      b = jmp[b][i];
    }
  if (a == b) return best;
  for (int i = MAXLOGN - 1; i >= 0; i--)
    if (jmp[a][i] != jmp[b][i]) {
      best = max(best, len[a][i]);
      best = max(best, len[b][i]);
      a = jmp[a][i];
      b = jmp[b][i];
    }
  return max(best, max(len[a][0], len[b][0]));
}
int find_parent(int x) {
  if (par[x] == x) return x;
  return par[x] = find_parent(par[x]);
}
bool merge(int a, int b) {
  a = find_parent(a), b = find_parent(b);
  if (a == b) return false;
  par[a] = b;
  return true;
}
void dfs(int cur, int prv) {
  for (auto e : adj[cur]) {
    int nxt = e.first, w = e.second;
    if (nxt == prv) continue;
    jmp[nxt][0] = cur;
    len[nxt][0] = w;
    dep[nxt] = dep[cur] + 1;
    dfs(nxt, cur);
  }
}
int main() {
  scanf("%d %d", &N, &M);
  for (int i = 0, a, b, e; i < M; i++) {
    scanf("%d %d %d", &a, &b, &e);
    E[i] = tuple<int, int, int, int>(e, a - 1, b - 1, i);
  }
  sort(E, E + M);
  for (int i = 0; i < N; i++) par[i] = i;
  for (int i = 0, w, a, b, idx; i < M; i++) {
    tie(w, a, b, idx) = E[i];
    if (merge(a, b)) {
      adj[a].emplace_back(b, w);
      adj[b].emplace_back(a, w);
    } else
      bad[idx] = true;
  }
  dfs(0, -1);
  process();
  for (int i = 0, w, a, b, idx; i < M; i++) {
    tie(w, a, b, idx) = E[i];
    if (bad[idx]) ans[idx] = query(a, b);
  }
  for (int i = 0; i < M; i++)
    if (bad[i]) printf("%d\n", ans[i]);
  return 0;
}
