#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 99;
const long long M = 1e6 + 99;
const long long Max = 1e9;
long long U, V;
struct edge {
  long long u, v, w;
  bool operator<(edge e) const {
    if (e.w == w) return (u == U && v == V);
    return e.w > w;
  }
} a[M];
long long n, m;
long long f[N];
long long Find(long long x) { return f[x] == x ? x : f[x] = Find(f[x]); }
bool F = 0;
bool format(long long mid) {
  for (long long i = 1; i <= n; i++) {
    f[i] = i;
  }
  for (long long i = 1; i <= m; i++) {
    if (a[i].u == U && a[i].v == V) {
      a[i].w = mid;
    }
  }
  sort(a + 1, a + 1 + m);
  long long cnt = 0;
  for (long long i = 1; i <= m; i++) {
    long long fx = Find(a[i].u);
    long long fy = Find(a[i].v);
    if (fx == fy)
      continue;
    else
      f[fx] = fy;
    if (a[i].u == U && a[i].v == V) return 1;
    cnt++;
    if (cnt == n - 1) break;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    if (i == 1) U = u, V = v;
    a[i] = {u, v, w};
  }
  long long l = 1, r = Max;
  long long ans = 0;
  while (l < r) {
    long long mid = (l + r) / 2;
    if (format(mid)) {
      l = mid + 1;
      ans = mid;
    } else
      r = mid;
  }
  if (format(l)) ans = l;
  cout << ans << endl;
}
