#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vb = vector<bool>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
vector<pair<pii, pii>> edgeList;
set<pii> queries;
vector<vector<pii>> mst;
int n, m, a, b, e;
vi par, level;
vvi lca, max_weight;
const int LOG_MAX = 20;
int find_parent(int a) {
  if (par[a] < 0) return a;
  return par[a] = find_parent(par[a]);
}
void join(int a, int b) {
  int par_a = find_parent(a);
  int par_b = find_parent(b);
  par[par_b] = par_a;
}
void buildMST() {
  int size = edgeList.size();
  for (int i = 0; i < size; i++) {
    auto edge = edgeList[i];
    pii p1, p2;
    tie(p1, p2) = edge;
    tie(a, b) = p2;
    e = p1.first;
    if (find_parent(a) != find_parent(b)) {
      join(a, b);
      mst[a].push_back({e, b});
      mst[b].push_back({e, a});
    } else {
      queries.insert({p1.second, i});
    }
  }
}
void dfs(int node, int lvl, int par = -1) {
  level[node] = lvl;
  lca[node][0] = par;
  for (pii p : mst[node]) {
    int to;
    tie(e, to) = p;
    if (to != par) {
      max_weight[to][0] = e;
      dfs(to, lvl + 1, node);
    }
  }
}
void init() {
  dfs(1, 0);
  for (int j = 1; j <= LOG_MAX - 1; j++) {
    for (int i = 1; i <= n; i++) {
      if (lca[i][j - 1] != -1) {
        lca[i][j] = lca[lca[i][j - 1]][j - 1];
        if (lca[i][j] != -1)
          max_weight[i][j] =
              max(max_weight[i][j - 1], max_weight[lca[i][j - 1]][j - 1]);
      }
    }
  }
}
int find_lca(int a, int b) {
  if (level[a] > level[b]) swap(a, b);
  for (int i = LOG_MAX - 1; i >= 0; i--)
    if (level[b] - level[a] >= (1 << i)) b = lca[b][i];
  if (a == b) return a;
  for (int i = LOG_MAX - 1; i >= 0; i--) {
    if (lca[a][i] != lca[b][i]) {
      a = lca[a][i], b = lca[b][i];
    }
  }
  if (a != b) a = lca[a][0];
  return a;
}
int calc(int a, int c) {
  int ret = 0;
  for (int i = LOG_MAX - 1; i >= 0; i--) {
    if (level[a] - level[c] >= (1 << i)) {
      ret = max(ret, max_weight[a][i]);
      a = lca[a][i];
    }
  }
  return ret;
}
int getAns(int a, int b) {
  int c = find_lca(a, b);
  return max(calc(a, c), calc(b, c));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  par.assign(n + 1, -1), level.assign(n + 1, -1), mst.resize(n + 1);
  lca.assign(n + 1, vi(LOG_MAX, -1)), max_weight.assign(n + 1, vi(LOG_MAX, -1));
  for (int i = 0; i < (int)m; i++) {
    cin >> a >> b >> e;
    edgeList.push_back({{e, i}, {a, b}});
  }
  sort(edgeList.begin(), edgeList.end(),
       [&](pair<pii, pii> p1, pair<pii, pii> p2) {
         return p1.first.first < p2.first.first;
       });
  buildMST();
  if (queries.empty()) return 0;
  init();
  for (auto p : queries) {
    int i = p.second;
    auto edge = edgeList[i];
    pii p1, p2;
    tie(p1, p2) = edge;
    tie(a, b) = p2;
    e = p1.first;
    cout << getAns(a, b) << '\n';
  }
  return 0;
}
