#include <bits/stdc++.h>
using namespace std;
const long long N = 100000, M = 1000000;
long long n, m;
struct corr {
  long long a, b, e;
} c[M + 1];
static bool comp(corr& a, corr& b) { return a.e < b.e; }
long long dsu[N + 1];
long long root(long long a) {
  while (a != dsu[a]) {
    dsu[a] = dsu[dsu[a]];
    a = dsu[a];
  }
  return a;
}
void join(long long a, long long b) {
  long long ra = root(a), rb = root(b);
  if (ra != rb) {
    dsu[ra] = rb;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (long long i = 0; i < m; ++i) {
    cin >> c[i].a >> c[i].b >> c[i].e;
  }
  for (long long i = 1; i <= n; ++i) dsu[i] = i;
  sort(c + 1, c + m, comp);
  long long i = 1;
  while (i < m) {
    long long j = i + 1;
    while (j < m && c[j].e == c[i].e) j++;
    for (long long ind = i; ind < j; ++ind) {
      join(c[ind].a, c[ind].b);
    }
    if (root(c[0].a) == root(c[0].b)) break;
    i = j;
  }
  long long ans;
  if (i == m) {
    ans = 1000000000;
  } else {
    ans = c[i].e;
  }
  cout << ans << endl;
  return 0;
}
