#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int M = 1e6 + 5;
const int step = 18;
int n, m, q, p[N];
int cnt, head[N], dep[N], father[N][step + 1], b[N][step + 1], ans[M];
inline int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
int find(int x) {
  if (p[x] != x) p[x] = find(p[x]);
  return p[x];
}
struct edge {
  int to, next, dis;
} e[N << 1];
inline void add_edge(int u, int v, int d) {
  cnt++;
  e[cnt].dis = d;
  e[cnt].to = v;
  e[cnt].next = head[u];
  head[u] = cnt;
}
inline void dfs(int u, int f) {
  dep[u] = dep[f] + 1;
  father[u][0] = f;
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == f) continue;
    b[v][0] = e[i].dis;
    dfs(v, u);
  }
}
inline int ask(int x, int y) {
  int ans = 0;
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 0; i < step + 1; i++)
    if ((1 << i) & (dep[x] - dep[y])) {
      ans = max(ans, b[x][i]);
      x = father[x][i];
    }
  if (x == y) return ans;
  for (int i = step; i >= 0; i--) {
    if (father[x][i] != father[y][i]) {
      ans = max(ans, max(b[x][i], b[y][i]));
      x = father[x][i];
      y = father[y][i];
    }
  }
  return max(ans, max(b[x][0], b[y][0]));
}
struct node {
  int u, v, d, id;
  bool fg;
} a[M];
bool cmp(node a, node b) { return a.d < b.d; }
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 1; i <= m; i++) {
    a[i].u = read();
    a[i].v = read();
    a[i].d = read();
    a[i].id = i;
  }
  sort(a + 1, a + m + 1, cmp);
  for (int i = 1; i <= m; i++) {
    int u = a[i].u, v = a[i].v, d = a[i].d;
    if (find(u) != find(v)) {
      add_edge(u, v, d);
      add_edge(v, u, d);
      p[find(u)] = p[v];
      a[i].fg = 1;
    }
  }
  dfs(1, 0);
  for (int i = 1; i <= step; i++) {
    for (int j = 1; j <= n; j++) {
      father[j][i] = father[father[j][i - 1]][i - 1];
      b[j][i] = max(b[j][i - 1], b[father[j][i - 1]][i - 1]);
    }
  }
  for (int i = 1; i <= m; i++) {
    if (a[i].fg == 0) {
      int x = a[i].u, y = a[i].v;
      ans[a[i].id] = ask(x, y);
    }
  }
  for (int i = 1; i <= m; i++) {
    if (ans[i] > 0) printf("%d ", ans[i]);
  }
  return 0;
}
