#include <bits/stdc++.h>
using namespace std;
long long p[300200];
long long lg = 19;
long long dp[300200][20];
long long mx[300200][20];
vector<pair<long long, long long> > g[300200];
map<pair<long long, long long>, long long> mp;
pair<long long, long long> par[300200];
long long h[300200];
map<long long, pair<long long, long long> > rmp;
void make_set(long long v) { p[v] = v; }
long long get(long long v) {
  if (v == p[v]) return v;
  return p[v] = get(p[v]);
}
void unite(long long a, long long b) {
  a = get(a);
  b = get(b);
  if (rand() & 1)
    p[a] = b;
  else
    p[b] = a;
}
void add(long long a, long long b, long long cost) {
  dp[b][0] = a;
  mx[b][0] = cost;
  for (long long i = 1; i <= lg; ++i) {
    dp[b][i] = dp[dp[b][i - 1]][i - 1];
    mx[b][i] = max(mx[dp[b][i - 1]][i - 1], mx[b][i - 1]);
  }
}
void dfs(long long v, long long pr = -1) {
  for (long long i = 0; i < g[v].size(); ++i) {
    long long to = g[v][i].first;
    long long cost = g[v][i].second;
    if (to == pr) continue;
    add(v, to, cost);
    h[to] = h[v] + 1;
    dfs(to, v);
  }
}
bool used[1300200];
long long lca(long long v, long long u) {
  long long ma = -2e9;
  if (h[v] > h[u]) swap(v, u);
  for (long long i = lg; i >= 0; --i) {
    if (h[u] - h[v] >= (1 << i)) {
      ma = max(ma, mx[u][i]);
      u = dp[u][i];
    }
  }
  if (u == v) {
    if (ma != -2e9)
      return ma;
    else
      return 0;
  }
  for (long long i = lg - 1; i >= 0; --i) {
    if (dp[v][i] != dp[u][i]) {
      ma = max(mx[u][i], ma);
      ma = max(mx[v][i], ma);
      v = dp[v][i];
      u = dp[u][i];
    }
  }
  if (u != v) ma = max({ma, mx[u][0], mx[v][0]});
  if (ma != -2e9)
    return ma;
  else
    return 0;
}
signed main() {
  srand(time(0));
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, pair<long long, long long> > > edges;
  for (long long i = 0; i < n; ++i) make_set(i);
  for (long long i = 0; i < m; ++i) {
    long long a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    if (a > b) swap(a, b);
    edges.push_back({c, {a, b}});
    mp[{a, b}] = i;
    rmp[i] = {a, b};
  }
  sort(edges.begin(), edges.end());
  for (long long i = 0; i < edges.size(); ++i) {
    long long c = edges[i].first;
    long long a = edges[i].second.first;
    long long b = edges[i].second.second;
    if (get(a) != get(b)) {
      unite(a, b);
      g[a].push_back({b, c});
      g[b].push_back({a, c});
      used[mp[{a, b}]] = 1;
    }
  }
  dfs(0);
  vector<pair<long long, long long> > ans;
  for (long long i = 0; i < m; ++i) {
    if (used[i]) {
      continue;
    }
    long long a = rmp[i].first;
    long long b = rmp[i].second;
    long long mm = lca(a, b);
    cout << mm << " ";
  }
  return 0;
}
