#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
const int M = 1e6 + 10;
long long qpow(long long x, long long y, long long MOD) {
  long long a = 1;
  while (y) {
    if (y & 1) a = a * x % MOD;
    x = x * x % MOD;
    y >>= 1;
  }
  return a;
}
int x, y;
int n, m, p[N];
int Find(int x) { return x == p[x] ? x : p[x] = Find(p[x]); }
struct Edge {
  int u, v;
  long long w;
  bool operator<(const Edge& r) const { return w < r.w; };
} E[M];
long long work() {
  for (int i = int(1); i <= int(n); ++i) p[i] = i;
  sort(E + 1, E + 1 + m);
  long long ans = 0;
  for (int i = int(1); i <= int(m); ++i) {
    int fx = Find(E[i].u), fy = Find(E[i].v);
    if (fx != fy) p[fx] = fy, ans += E[i].w;
  }
  return ans;
}
void upd(long long val) {
  for (int i = int(1); i <= int(m); ++i) {
    if (E[i].u == x && E[i].v == y) {
      E[i].w = val;
      break;
    }
  }
}
bool chk(int mid) {
  upd(mid);
  long long tp = work();
  upd(INF);
  long long tp2 = work();
  if (tp < tp2)
    return true;
  else
    return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = int(1); i <= int(m); ++i) {
    scanf("%d%d%lld", &E[i].u, &E[i].v, &E[i].w);
    if (i == 1) x = E[i].u, y = E[i].v;
  }
  if (m == n - 1) {
    puts("1000000000");
    return 0;
  }
  int L = 0, R = 1e9, ans = -1;
  while (L <= R) {
    int mid = (L + R) >> 1;
    if (chk(mid))
      L = mid + 1, ans = mid;
    else
      R = mid - 1;
  }
  printf("%d\n", min(ans + 1, 1000000000));
  return 0;
}
