#include <bits/stdc++.h>
using namespace std;
const int maxn = 100050;
const long long mod = 1e9 + 7;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, m;
int f[maxn];
int findf(int x) { return f[x] == x ? x : f[x] = findf(f[x]); }
struct edge {
  int u;
  int v;
  long long w;
  int id;
  friend bool operator<(edge a, edge b) { return a.w < b.w; }
} e[maxn * 10];
bool chs[maxn * 10];
bool cmp(edge a, edge b) { return a.id < b.id; }
int dep[maxn];
int fa[maxn][25];
long long fw[maxn][25];
struct te {
  int v;
  long long w;
} now, nxt;
vector<te> g[maxn];
void dfs(int x, int p) {
  int k = 0;
  while (fa[x][k] && fa[fa[x][k]][k]) {
    fa[x][k + 1] = fa[fa[x][k]][k];
    fw[x][k + 1] = max(fw[x][k], fw[fa[x][k]][k]);
    k++;
  }
  int sz = g[x].size();
  int v = 0;
  for (int i = 0; i <= sz - 1; i++) {
    v = g[x][i].v;
    if (v == p) continue;
    fa[v][0] = x;
    fw[v][0] = g[x][i].w;
    dep[v] = dep[x] + 1;
    dfs(v, x);
  }
}
long long getans(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  long long mx = 0;
  int k = 0, dif = dep[u] - dep[v];
  int ru = u, rv = v;
  while (dif) {
    if (dif & 1) {
      mx = max(fw[u][k], mx);
      u = fa[u][k];
    }
    dif >>= 1;
    k++;
  }
  if (u == v) return mx;
  k = 0;
  while (k >= 0) {
    if (fa[u][k] != fa[v][k]) {
      mx = max(mx, fw[u][k]);
      mx = max(mx, fw[v][k]);
      u = fa[u][k];
      v = fa[v][k];
      k++;
    } else {
      k--;
    }
  }
  mx = max(mx, fw[u][0]);
  mx = max(mx, fw[v][0]);
  return mx;
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    e[i].u = read();
    e[i].v = read();
    e[i].w = read();
    e[i].id = i;
  }
  for (int i = 1; i <= n; i++) {
    f[i] = i;
  }
  sort(e + 1, e + 1 + m);
  for (int i = 1; i <= m; i++) {
    int u = e[i].u;
    int v = e[i].v;
    int fu = findf(u), fv = findf(v);
    if (fu == fv) continue;
    f[fu] = fv;
    chs[e[i].id] = true;
    now.w = e[i].w;
    now.v = v;
    g[u].push_back(now);
    now.v = u;
    g[v].push_back(now);
  }
  dfs(1, 0);
  sort(e + 1, e + 1 + m, cmp);
  for (int i = 1; i <= m; i++) {
    if (chs[i]) continue;
    printf("%I64d\n", getans(e[i].u, e[i].v));
  }
  return 0;
}
