#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long MOD = 1000000007, LOG = 19;
vector<pair<pair<long long, long long>, pair<long long, long long> > > edges;
long long p[100005], up[100005][LOG], maxi[100005][LOG], in[100005],
    out[100005], idx, ans[1000001];
vector<vector<pair<long long, long long> > > vec;
vector<long long> nt;
long long findSet(long long i) {
  if (p[i] == i) return i;
  return p[i] = findSet(p[i]);
}
bool is_ances(long long a, long long b) {
  return ((in[a] <= in[b]) && (out[a] >= out[b]));
}
void dfs(long long node, long long par, long long w) {
  in[node] = idx++;
  up[node][0] = par, maxi[node][0] = w;
  for (long long i = 1; i < LOG; ++i) up[node][i] = up[up[node][i - 1]][i - 1];
  for (long long i = 1; i < LOG; ++i)
    maxi[node][i] = max(maxi[node][i - 1], maxi[up[node][i - 1]][i - 1]);
  for (auto it : vec[node])
    if (it.second != par) dfs(it.second, node, it.first);
  out[node] = idx++;
}
long long lca(long long a, long long b) {
  if (is_ances(a, b)) return a;
  if (is_ances(b, a)) return b;
  for (long long i = LOG - 1; i >= 0; i--)
    if (!is_ances(up[a][i], b)) a = up[a][i];
  return up[a][0];
}
long long get_max(long long a, long long b) {
  if (a == b) return 0;
  long long ans = 0;
  for (long long i = LOG - 1; i >= 0; i--)
    if (!is_ances(up[a][i], b)) ans = max(ans, maxi[a][i]), a = up[a][i];
  return max(ans, maxi[a][0]);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m, a, b, w;
  cin >> n >> m;
  for (long long i = 0; i < n; ++i) p[i] = i;
  edges.resize(m), vec.resize(n);
  for (long long i = 0; i < m; ++i) {
    ans[i] = -1;
    cin >> a >> b >> w;
    a--, b--;
    edges[i] = {pair<long long, long long>(w, i),
                pair<long long, long long>(a, b)};
  }
  sort((edges).begin(), (edges).end());
  for (long long i = 0; i < m; ++i) {
    a = findSet(edges[i].second.first);
    b = findSet(edges[i].second.second);
    if (a == b) {
      nt.push_back(i);
      continue;
    }
    p[a] = b;
    vec[edges[i].second.first].push_back(pair<long long, long long>(
        edges[i].first.first, edges[i].second.second));
    vec[edges[i].second.second].push_back(pair<long long, long long>(
        edges[i].first.first, edges[i].second.first));
  }
  dfs(0, 0, 0);
  for (auto it : nt) {
    a = edges[it].second.first, b = edges[it].second.second;
    long long l = lca(a, b);
    ans[edges[it].first.second] = max(get_max(a, l), get_max(b, l));
  }
  for (long long i = 0; i < m; ++i) {
    if (ans[i] == -1) continue;
    cout << ans[i] << " ";
  }
  return 0;
}
