#include <bits/stdc++.h>
using namespace std;
void FileIO() {}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int n, m;
const int N = 100005, M = 2000005;
int X, Y, Z;
int head[N], cnt;
struct e {
  int t, next, w;
} edge[M];
struct node {
  int f, t, w, id;
  bool operator<(const node& no) const { return w < no.w; }
} eg[M], Edge[M];
int fa[N], vis[M];
int findroot(int x) {
  if (fa[x] == x) return x;
  return fa[x] = findroot(fa[x]);
}
bool merge(int x, int y) {
  int fax = findroot(x);
  int fay = findroot(y);
  if (fax != fay) {
    fa[fax] = fay;
    return true;
  }
  return false;
}
void add(int f, int t, int w) {
  edge[cnt].t = t;
  edge[cnt].w = w;
  edge[cnt].next = head[f];
  head[f] = cnt++;
}
void kruskal() {
  int tot = 0;
  for (int i = 1; i <= m; i++) {
    if (tot == n - 1) break;
    int u = eg[i].f, v = eg[i].t, w = eg[i].w;
    if (X == u && v == Y) continue;
    if (merge(u, v)) {
      vis[eg[i].id] = 1;
      tot += 1;
      add(u, v, w);
      add(v, u, w);
    }
  }
  if (tot != n - 1) {
    cout << 1000000000 << endl;
    exit(0);
  }
}
int dfn[N], bz[N][25], dp[N][25];
void dfs(int root, int deep) {
  dfn[root] = deep;
  for (int i = head[root]; i != -1; i = edge[i].next) {
    int v = edge[i].t, w = edge[i].w;
    if (!dfn[v]) {
      bz[v][0] = root;
      dp[v][0] = w;
      dfs(v, deep + 1);
    }
  }
}
void deal() {
  for (int i = 1; i <= 20; i++) {
    for (int j = 1; j <= n; j++) {
      bz[j][i] = bz[bz[j][i - 1]][i - 1];
      dp[j][i] = max(dp[j][i - 1], dp[bz[j][i - 1]][i - 1]);
    }
  }
}
int LCA(int x, int y) {
  int ans = 0;
  if (dfn[x] < dfn[y]) swap(x, y);
  for (int i = 20; i >= 0; i--) {
    if (dfn[bz[x][i]] >= dfn[y]) {
      ans = max(ans, dp[x][i]);
      x = bz[x][i];
    }
  }
  if (x == y) return ans;
  for (int i = 20; i >= 0; i--) {
    if (bz[x][i] ^ bz[y][i]) {
      ans = max(ans, dp[x][i]);
      ans = max(ans, dp[y][i]);
      x = bz[x][i];
      y = bz[y][i];
    }
  }
  ans = max(ans, dp[x][0]);
  ans = max(ans, dp[y][0]);
  return ans;
}
void Init() {
  memset(head, -1, sizeof(head)), cnt = 0;
  for (int i = 1; i <= n; i++) fa[i] = i;
}
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  Init();
  for (int i = 1; i <= m; i++) {
    cin >> eg[i].f >> eg[i].t >> eg[i].w;
    eg[i].id = i;
    Edge[i] = eg[i];
  }
  if (m == n - 1) return 0;
  sort(eg + 1, eg + 1 + m);
  kruskal();
  dfs(1, 1);
  deal();
  for (int i = 1; i <= m; i++)
    if (!vis[i]) cout << LCA(Edge[i].f, Edge[i].t) << endl;
}
