#include <bits/stdc++.h>
std::pair<std::pair<int, int>, int> edg[1000006];
int par[1000006], sz[1000006];
int n, m;
void init() {
  for (int i = 1; i <= n; i++) {
    par[i] = i;
    sz[i] = 1;
  }
}
int root(int node) {
  if (node != par[node]) {
    par[node] = root(par[node]);
  }
  return par[node];
}
void join(int x, int y) {
  x = root(x);
  y = root(y);
  if (x != y) {
    if (sz[x] < sz[y]) std::swap(x, y);
    par[y] = x;
    sz[x] = sz[x] + sz[y];
  }
}
bool ok(long long val) {
  init();
  edg[0].second = val;
  int i, u, v;
  std::vector<std::pair<int, int> > kru;
  for (i = 0; i < m; i++) {
    kru.push_back({edg[i].second, i});
  }
  std::sort(kru.begin(), kru.end());
  for (auto front : kru) {
    u = edg[front.second].first.first;
    v = edg[front.second].first.second;
    if (root(u) != root(v)) {
      if (front.second == 0) return true;
      join(u, v);
    }
  }
  return false;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  int i, x, y, c;
  std::cin >> n >> m;
  for (i = 0; i < m; i++) {
    std::cin >> x >> y >> c;
    edg[i] = {{x, y}, c};
  }
  int l, r, mid;
  l = 0;
  r = 1e9;
  while (l < r) {
    mid = l + (r - l + 1) / 2;
    if (ok(mid)) {
      l = mid;
    } else {
      r = mid - 1;
    }
  }
  std::cout << l;
  return 0;
}
