#include <bits/stdc++.h>
const long long INF = 2000000007;
const long long BIG_INF = 2000000000000000005;
const long long mod = 1000000007;
const long long P = 31;
const long double PI = 3.141592653589793238462643;
using namespace std;
vector<pair<long long, long long> > dir = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
bool valid(long long x, long long y, long long n, long long m) {
  return x >= 0 && y >= 0 && x < n && y < m;
}
mt19937 rng(1999999973);
const int N = 100000 + 5, M = 1000000 + 5, Lg = 17;
int n, m, h[N], dp[N][Lg], mx[N][Lg], p[N], order[M], U[M], V[M], W[M];
vector<pair<long long, long long> > g[N];
bool good[M];
int lca(int u, int v) {
  if (h[u] < h[v]) swap(u, v);
  for (int j = Lg - 1; j >= 0; j--) {
    if (h[dp[u][j]] >= h[v]) u = dp[u][j];
  }
  if (u == v) return u;
  for (int j = Lg - 1; j >= 0; j--) {
    if (dp[u][j] != dp[v][j]) u = dp[u][j], v = dp[v][j];
  }
  return dp[u][0];
}
int find_set(int v) {
  if (p[v] == v) return v;
  p[v] = find_set(p[v]);
  return p[v];
}
bool comp(int x, int y) { return W[x] < W[y]; }
void dfs(int v, int pr, int ds, int w) {
  dp[v][0] = pr;
  mx[v][0] = w;
  h[v] = ds;
  for (int i = 0; i < g[v].size(); i++) {
    if (g[v][i].first != pr) dfs(g[v][i].first, v, ds + 1, g[v][i].second);
  }
}
void precalc() {
  for (int j = 1; j < Lg; j++) {
    for (int i = 0; i < n; i++) {
      dp[i][j] = dp[dp[i][j - 1]][j - 1];
      mx[i][j] = max(mx[i][j - 1], mx[dp[i][j - 1]][j - 1]);
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    order[i] = i;
    cin >> U[i] >> V[i] >> W[i];
    U[i]--, V[i]--;
  }
  for (int i = 0; i < n; i++) p[i] = i;
  sort(order, order + m, comp);
  for (int i = 0; i < m; i++) {
    int cur = order[i];
    if (find_set(U[cur]) != find_set(V[cur])) {
      g[U[cur]].push_back(make_pair(V[cur], W[cur]));
      g[V[cur]].push_back(make_pair(U[cur], W[cur]));
      p[find_set(U[cur])] = find_set(V[cur]);
      good[cur] = true;
    }
  }
  dfs(0, 0, 0, -INF);
  precalc();
  for (int i = 0; i < m; i++) {
    if (good[i]) continue;
    int lc = lca(U[i], V[i]);
    int ans = -INF;
    int cur = h[U[i]] - h[lc], u = U[i], v = V[i];
    while (cur > 0) {
      ans = max(ans, mx[u][__builtin_ctz(cur)]);
      u = dp[u][__builtin_ctz(cur)];
      cur &= (cur - 1);
    }
    u = v;
    cur = h[v] - h[lc];
    while (cur > 0) {
      ans = max(ans, mx[u][__builtin_ctz(cur)]);
      u = dp[u][__builtin_ctz(cur)];
      cur &= (cur - 1);
    }
    cout << ans << '\n';
  }
  return 0;
}
