#include <bits/stdc++.h>
using namespace std;
long long p[300200];
void make_set(long long v) { p[v] = v; }
long long get(long long v) {
  if (v == p[v]) return v;
  return p[v] = get(p[v]);
}
void unite(long long a, long long b) {
  a = get(a);
  b = get(b);
  if (rand() & 1)
    p[a] = b;
  else
    p[b] = a;
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  long long n, m;
  cin >> n >> m;
  pair<long long, pair<long long, long long> > f1;
  vector<pair<long long, pair<long long, long long> > > edges;
  for (long long i = 0; i < n; ++i) make_set(i);
  for (long long i = 0; i < m; ++i) {
    long long a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    if (i == 0)
      f1 = {c, make_pair(a, b)};
    else
      edges.push_back({c, {a, b}});
  }
  long long mod = 1e9;
  sort(edges.begin(), edges.end());
  for (long long i = 0; i < edges.size(); ++i) {
    long long c = edges[i].first;
    long long a = edges[i].second.first;
    long long b = edges[i].second.second;
    if (get(a) != get(b)) {
      unite(a, b);
    }
    if (get(f1.second.first) == get(f1.second.second)) {
      mod = min(mod, c);
    }
  }
  cout << mod;
  return 0;
}
