#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
struct kek {
  int x, y, len, ind;
};
vector<kek> r;
vector<pair<int, int>> g[N];
bool cmp(const kek &a, const kek &b) { return a.len < b.len; }
bool cmp1(const kek &a, const kek &b) { return a.ind < b.ind; }
int p[N];
int root(int x) {
  if (p[x] == x) return x;
  return p[x] = root(p[x]);
}
void uni(int x, int y) {
  x = root(x), y = root(y);
  p[x] = y;
}
int lev[N];
int min_val[N][30];
int pc[N];
bool us[N];
int sz = 0;
int centr = 0;
int gdeep = 0;
void dfs_sz(int x, int pr) {
  sz++;
  for (int i = 0; i < g[x].size(); i++) {
    int y = g[x][i].first;
    if (y != pr && !us[y]) {
      dfs_sz(y, x);
    }
  }
}
void dfs_mx(int x, int pr, int mx) {
  min_val[x][gdeep] = mx;
  for (int i = 0; i < g[x].size(); i++) {
    int y = g[x][i].first;
    if (y != pr && !us[y]) {
      dfs_mx(y, x, max(mx, g[x][i].second));
    }
  }
}
int dfs(int x, int pr) {
  int dp = 1;
  int mx = 0;
  for (int i = 0; i < g[x].size(); i++) {
    int y = g[x][i].first;
    if (y != pr && !us[y]) {
      int dp1 = dfs(y, x);
      mx = max(mx, dp1);
      dp += dp1;
    }
  }
  if (mx * 2 <= sz && 2 * (sz - dp) <= sz) {
    centr = x;
  }
  return dp;
}
int n;
void bu(int x, int prec, int deep) {
  gdeep = deep;
  sz = 0;
  dfs_sz(x, -1);
  centr = 0;
  dfs(x, -1);
  x = centr;
  lev[x] = deep;
  us[x] = 1;
  pc[x] = prec;
  dfs_mx(x, -1, -1);
  for (int i = 0; i < g[x].size(); i++) {
    int y = g[x][i].first;
    if (!us[y]) {
      bu(y, x, deep + 1);
    }
  }
}
int getCenter(int a, int b) {
  while (lev[a] > lev[b]) a = pc[a];
  while (lev[a] < lev[b]) b = pc[b];
  while (a != b) a = pc[a], b = pc[b];
  return a;
}
int ans;
void dfs1(int x, int y, int pr, int t) {
  if (x == y) ans = max(ans, t);
  for (int i = 0; i < g[x].size(); i++) {
    int xx = g[x][i].first, len = g[x][i].second;
    if (xx != pr) {
      dfs1(xx, y, x, max(t, len));
    }
  }
}
int main() {
  int m;
  scanf("%d %d", &n, &m);
  for (int x = 1; x <= n; x++) {
    for (int i = 0; i < 30; i++) {
      min_val[x][i] = 1e9;
    }
  }
  for (int i = 0; i < m; i++) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    r.push_back({x, y, z, i});
  }
  sort(r.begin(), r.end(), cmp);
  vector<int> indx;
  for (int x = 1; x <= n; x++) {
    p[x] = x;
  }
  for (int i = 0; i < r.size(); i++) {
    int x = r[i].x, y = r[i].y, len = r[i].len;
    if (root(x) != root(y)) {
      uni(x, y);
      g[x].push_back({y, len});
      g[y].push_back({x, len});
    } else {
      indx.push_back(r[i].ind);
    }
  }
  sort(indx.begin(), indx.end());
  bu(1, -1, 0);
  sort(r.begin(), r.end(), cmp1);
  for (int ind : indx) {
    int x = r[ind].x, y = r[ind].y;
    int c = getCenter(x, y);
    cout << max(min_val[x][lev[c]], min_val[y][lev[c]]) << endl;
  }
  return 0;
}
