#include <bits/stdc++.h>
using namespace std;
long long id[100005], nodes, edges;
vector<pair<long long, pair<long long int, long long int>>> p;
void initialize() {
  for (long long i = 0; i < 100005; ++i) id[i] = i;
}
long long root(long long x) {
  while (id[x] != x) {
    id[x] = id[id[x]];
    x = id[x];
  }
  return x;
}
void union1(long long x, long long y) {
  long long p = root(x);
  long long q = root(y);
  id[p] = id[q];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long ans;
    cin >> nodes >> edges;
    if (edges == 1) {
      cout << 1000000000 << '\n';
      exit(0);
    }
    long long u, v, we;
    cin >> u >> v >> we;
    initialize();
    for (long long int i = 0; i < edges - 1; i++) {
      long long x, y, w;
      cin >> x >> y >> w;
      p.push_back({w, {x, y}});
    }
    sort((p).begin(), (p).end());
    long long x, y;
    long long cost, minimumCost = 0;
    for (long long i = 0; i < edges - 1; ++i) {
      x = p[i].second.first;
      y = p[i].second.second;
      cost = p[i].first;
      if (root(x) != root(y)) {
        minimumCost += cost;
        union1(x, y);
        if (root(u) == root(v)) {
          cout << cost << '\n';
          return 0;
        }
      }
    }
    cout << 1000000000 << '\n';
  }
  return 0;
}
