#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
int par[N];
pair<int, pair<int, int> > edges[N];
int n, m;
int fp(int x) {
  while (par[x] != x) {
    par[x] = par[par[x]];
    x = par[x];
  }
  return x;
}
void union1(int a, int b) {
  int x = fp(a);
  int y = fp(b);
  par[x] = par[y];
}
void solve() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) par[i] = i;
  for (int i = 0; i < m; i++) {
    cin >> edges[i].second.first >> edges[i].second.second >> edges[i].first;
  }
  sort(edges + 1, edges + m);
  int x = edges[0].second.first, y = edges[0].second.second;
  for (int i = 1; i < m; i++) {
    union1(edges[i].second.first, edges[i].second.second);
    if (fp(x) == fp(y)) {
      cout << edges[i].first << endl;
      return;
    }
  }
  cout << 1000000000 << endl;
}
int main() {
  int T = 1;
  while (T--) solve();
  return 0;
}
