#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 700;
long long par[M];
void init() {
  for (int i = 0; i < M; i++) par[i] = i;
}
long long root(long long x) {
  if (par[x] == x) return x;
  return par[x] = root(par[x]);
}
void U(long long x, long long y) {
  x = root(x);
  y = root(y);
  par[x] = y;
}
bool check(long long x, long long y, long long wt, long long m,
           vector<pair<long long, pair<long long, long long>>> &v) {
  init();
  for (int i = 0; i < m; i++) {
    long long w = v[i].first;
    if (w >= wt) {
      if (root(x) != root(y)) {
        return 1;
      } else
        return 0;
    }
    long long xx = v[i].second.first;
    long long yy = v[i].second.second;
    if (root(xx) != root(yy)) {
      U(xx, yy);
    }
  }
  return 0;
}
int main() {
  vector<pair<long long, pair<long long, long long>>> v;
  long long n, m, x, y, z, a, b, w;
  cin >> n >> m;
  cin >> a >> b >> w;
  for (int i = 1; i < m; i++) cin >> x >> y >> z, v.push_back({z, {y, x}});
  if (m == 1 || n - 1 == m) {
    cout << 1000000000;
    return 0;
  }
  sort(v.begin(), v.end());
  long long l = 0, r = 1e9, mid, ans = 0;
  while (l <= r) {
    mid = l + r >> 1;
    if (check(a, b, mid, m - 1, v))
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  cout << ans;
}
