#include <bits/stdc++.h>
int whois[100005];
struct Edge {
  int w, x, y;
  friend bool operator<(Edge a, Edge b) { return a.w < b.w; }
};
int find(int x) {
  if (whois[x] == x)
    return x;
  else
    return whois[x] = find(whois[x]);
}
using std::vector;
vector<Edge> edge;
int main(void) {
  int n, m, cnt = 0;
  Edge te, ew;
  scanf("%d%d", &n, &m);
  edge.reserve(m + 1);
  for (int i = 0; i < m; i++)
    scanf("%d%d%d", &ew.x, &ew.y, &ew.w), edge.push_back(ew);
  te = edge[0];
  edge[0].w = 1000000005;
  std::sort(edge.begin(), edge.end());
  int beg = 0, end = 1000000000;
  auto pre = edge.end() - 1;
  while (beg < end) {
    bool flag = 0;
    cnt = 0;
    te.w = (beg + end + 1) / 2;
    edge.erase(pre);
    edge.insert(pre = std::lower_bound(edge.begin(), edge.end(), te), te);
    for (int i = 0; i <= n; i++) whois[i] = i;
    for (auto e = edge.begin(); e < edge.end(); ++e) {
      if (find((*e).x) != find((*e).y)) {
        if (e == pre) {
          flag = 1;
          break;
        }
        whois[find((*e).y)] = find((*e).x);
        ++cnt;
        if (cnt == n - 1) {
          break;
        }
      }
    }
    if (flag) {
      beg = te.w;
    } else
      end = te.w - 1;
  }
  printf("%d", beg);
  return 0;
}
