#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int a, b, e, i;
};
class UnionFind {
 private:
  vector<int> p, r;

 public:
  UnionFind(int n) {
    r.assign(n, 0);
    p.assign(n, 0);
    iota(begin(p), end(p), 0);
  }
  int findset(int i) { return (p[i] == i) ? i : (p[i] = findset(p[i])); }
  bool unionset(int i, int j) {
    int x = findset(i), y = findset(j);
    if (x != y) {
      if (r[x] > r[y])
        p[y] = x;
      else {
        p[x] = y;
        if (r[x] == r[y]) ++r[y];
      }
      return true;
    } else
      return false;
  }
};
const int N = 1e5 + 10;
const int lgN = 18;
const int M = 1e6 + 10;
int n, m;
vector<Edge> el;
vector<pair<int, int> > al[N];
bool used[M];
int d[N];
pair<int, int> pa[N][lgN];
void dfs(int u) {
  for (int k = 1; k <= lgN - 1; ++k)
    pa[u][k] = pair<int, int>(
        pa[pa[u][k - 1].first][k - 1].first,
        max(pa[u][k - 1].second, pa[pa[u][k - 1].first][k - 1].second));
  for (auto v : al[u])
    if (v.first != pa[u][0].first)
      d[v.first] = d[u] + 1, pa[v.first][0] = pair<int, int>(u, v.second),
      dfs(v.first);
}
int ans(int a, int b) {
  if (d[a] < d[b]) swap(a, b);
  int maxi = 0;
  for (int k = lgN - 1; k >= 0; --k)
    if (pa[a][k].first != 0 and d[pa[a][k].first] >= d[b])
      maxi = max(maxi, pa[a][k].second), a = pa[a][k].first;
  if (a == b) return maxi;
  for (int k = lgN - 1; k >= 0; --k)
    if (pa[a][k].first != 0 and pa[b][k].first != 0 and
        pa[a][k].first != pa[b][k].first)
      maxi = max(maxi, max(pa[a][k].second, pa[b][k].second)),
      a = pa[a][k].first, b = pa[b][k].first;
  maxi = max(maxi, max(pa[a][0].second, pa[b][0].second));
  return maxi;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i <= m - 1; ++i) {
    int a, b, e;
    cin >> a >> b >> e;
    el.push_back({a, b, e, i});
  }
  sort(begin(el), end(el), [](Edge a, Edge b) {
    if (a.e == b.e)
      return a.i < b.i;
    else
      return a.e < b.e;
  });
  UnionFind UF(n + 1);
  for (auto& e : el) {
    if (UF.unionset(e.a, e.b))
      used[e.i] = 1, al[e.a].emplace_back(e.b, e.e),
      al[e.b].emplace_back(e.a, e.e);
  }
  d[1] = 0;
  dfs(1);
  sort(begin(el), end(el), [](Edge a, Edge b) { return a.i < b.i; });
  for (int i = 0; i <= m - 1; ++i)
    if (!used[i]) cout << ans(el[i].a, el[i].b) << '\n';
}
