#include <bits/stdc++.h>
using namespace std;
struct Node {
  int u, v, w, id;
  Node() {}
  Node(int _u, int _v, int _w, int _id) {
    u = _u;
    v = _v;
    w = _w;
    id = _id;
  }
  bool operator<(const Node &a) const { return w > a.w; }
};
int ar[5];
char buff[100];
void readLine() {
  gets(buff);
  int i = 0, len = strlen(buff), m = 0;
  while (i < len)
    if (buff[i] != ' ') {
      ar[m] = 0;
      while (i < len && buff[i] != ' ') ar[m] = ar[m] * 10 + buff[i++] - 48;
      m++;
    } else
      i++;
}
void printLine(int n) {
  int m = 0;
  do {
    buff[m++] = n % 10 + 48;
    n /= 10;
  } while (n);
  while (m--) putchar(buff[m]);
  putchar('\n');
}
int n, lab[1000100], depth[1000100];
pair<int, pair<int, int> > e[1000100 << 1];
vector<pair<int, int> > adj[1000100];
int P[1000100][21], L[1000100][21], k;
int getRoot(int u) {
  if (lab[u] < 0) return u;
  return lab[u] = getRoot(lab[u]);
}
void unionSet(int r1, int r2) {
  int x = lab[r1] + lab[r2];
  if (lab[r1] > lab[r2]) {
    lab[r1] = r2;
    lab[r2] = x;
  } else {
    lab[r1] = x;
    lab[r2] = r1;
  }
}
void dfs(int u, int p, int cost, int lvl) {
  P[u][0] = p;
  L[u][0] = cost;
  depth[u] = lvl;
  for (int i = 0, _n = (adj[u].size()); i < _n; i++) {
    int v = adj[u][i].first;
    if (v != p) dfs(v, u, adj[u][i].second, lvl + 1);
  }
}
void buildLCA() {
  dfs(1, -1, 0, 0);
  for (k = 0; (1 << (k + 1)) <= n; k++)
    ;
  for (int j = (1), _b = (k); j <= _b; j++) {
    for (int i = (1), _b = (n); i <= _b; i++)
      if (P[i][j - 1] == -1) {
        P[i][j] = P[i][j - 1];
        L[i][j] = L[i][j - 1];
      } else {
        P[i][j] = P[P[i][j - 1]][j - 1];
        L[i][j] = max(L[i][j - 1], L[P[i][j - 1]][j - 1]);
      }
  }
}
int solve(int u, int v) {
  int res = 0;
  if (depth[v] > depth[u]) swap(u, v);
  for (int j = (k), _b = (0); j >= _b; j--)
    if (P[u][j] != -1 && depth[u] - (1 << (j)) >= depth[v]) {
      res = max(res, L[u][j]);
      u = P[u][j];
    }
  if (u == v) return res;
  for (int j = (k), _b = (0); j >= _b; j--)
    if (P[u][j] != -1 && P[u][j] != P[v][j]) {
      res = max(res, max(L[u][j], L[v][j]));
      u = P[u][j];
      v = P[v][j];
    }
  res = max(res, L[u][0]);
  res = max(res, L[v][0]);
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int cases, caseNo = 1, m, u, v;
  while (caseNo--) {
    cin >> n >> m;
    for (int i = (1), _b = (n); i <= _b; i++) {
      lab[i] = -1;
      adj[i].clear();
    }
    priority_queue<Node> pq;
    for (int i = 0, _n = (m); i < _n; i++) {
      cin >> ar[0] >> ar[1] >> ar[2];
      pq.push(Node(ar[0], ar[1], ar[2], i));
    }
    vector<pair<int, pair<int, int> > > stor;
    while (!pq.empty()) {
      Node temp = pq.top();
      u = getRoot(temp.u);
      v = getRoot(temp.v);
      pq.pop();
      if (u != v) {
        unionSet(u, v);
        adj[temp.u].push_back(pair<int, int>(temp.v, temp.w));
        adj[temp.v].push_back(pair<int, int>(temp.u, temp.w));
      } else {
        stor.push_back({temp.id, {temp.u, temp.v}});
      }
    }
    int ans[m + 1];
    memset(ans, -1, sizeof ans);
    buildLCA();
    int d = stor.size();
    for (int i = 0; i < d; i++) {
      ans[stor[i].first] = (solve(stor[i].second.first, stor[i].second.second));
    }
    for (int i = 0; i < m; i++) {
      if (ans[i] != -1) cout << ans[i] << endl;
    }
  }
  return 0;
}
