#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const int maxn = 1000000 + 9;
const double pi = 3.14159265358979323846264338328;
const int inf = int(1e9);
int pq[maxn], jk[maxn];
int fg(int p) {
  if (pq[p] == p)
    return p;
  else
    return pq[p] = fg(pq[p]);
}
void unite(int x, int y) {
  x = fg(x);
  y = fg(y);
  if (x == y) return;
  if (jk[x] < jk[y]) {
    pq[x] = y;
  } else {
    pq[y] = x;
    if (jk[x] == jk[y]) jk[x]++;
  }
}
bool same(int x, int y) {
  if (fg(x) == fg(y))
    return true;
  else
    return false;
}
struct edge {
  int u, v, cost, id;
};
bool cmp(const edge &a, const edge &b) {
  if (a.cost != b.cost) return a.cost < b.cost;
  return a.id < b.id;
}
int n, m, vis[maxn], kl[maxn];
edge op[maxn], io[maxn];
void sol() {
  memset(jk, 0, sizeof(jk));
  for (int i = 1; i <= n; ++i) pq[i] = i;
  for (int i = 1; i <= n; ++i) kl[i] = inf;
  sort(op, op + m, cmp);
  int num = 0;
  for (int i = 0; i < m; ++i) {
    if (!same(op[i].u, op[i].v)) {
      vis[op[i].id] = 1;
      unite(op[i].u, op[i].v);
      ++num;
      if (num == n - 1) break;
    }
  }
}
vector<pair<int, int> > g[maxn];
int parent[20][int(1e5) + 9], gh[20][int(1e5) + 9], depth[int(1e5) + 9];
void dfs(int u, int v, int d, int w) {
  parent[0][u] = v;
  depth[u] = d;
  gh[0][u] = w;
  for (int i = 0; i < g[u].size(); ++i) {
    pair<int, int> e = g[u][i];
    if (e.first != v) dfs(e.first, u, d + 1, e.second);
  }
}
void init(int n) {
  dfs(1, -1, 0, -1);
  for (int i = 1; i < 20; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (parent[i - 1][j] < 0)
        parent[i][j] = gh[i][j] = -1;
      else {
        int v = parent[i - 1][j];
        gh[i][j] = max(gh[i - 1][j], gh[i - 1][v]);
        parent[i][j] = parent[i - 1][v];
      }
    }
  }
}
int sol(int u, int v) {
  if (depth[u] > depth[v]) swap(u, v);
  int ans = -1;
  for (int i = 0; i < 20; ++i) {
    if ((depth[v] - depth[u]) >> i & 1) {
      ans = max(ans, gh[i][v]);
      v = parent[i][v];
    }
  }
  if (u == v) return ans;
  for (int i = 19; i >= 0; --i) {
    if (parent[i][u] != parent[i][v]) {
      ans = max(gh[i][u], ans);
      ans = max(ans, gh[i][v]);
      u = parent[i][u];
      v = parent[i][v];
    }
  }
  return max(max(ans, gh[0][u]), gh[0][v]);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i)
    scanf("%d%d%d", &op[i].u, &op[i].v, &op[i].cost), op[i].id = i,
                                                      io[i] = op[i];
  sol();
  for (int i = 0; i < m; ++i) {
    if (vis[i]) {
      int u = io[i].u, v = io[i].v;
      g[u].push_back(make_pair(v, io[i].cost));
      g[v].push_back(make_pair(u, io[i].cost));
    }
  }
  init(n);
  for (int i = 0; i < m; ++i) {
    if (!vis[i]) {
      int u = io[i].u, v = io[i].v;
      printf("%d\n", sol(u, v));
    }
  }
  return 0;
}
