#include <bits/stdc++.h>
const int N = 200001;
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
int par[N];
int p(int u) {
  if (par[u] == u) return u;
  par[u] = p(par[u]);
  return par[u];
}
void un(int u, int v) {
  int pu = p(u), pv = p(v);
  if (pu != pv) {
    par[pu] = pv;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  pair<int, int> ed[m], a[m];
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    ed[i] = make_pair(u, v);
    a[i] = make_pair(w, i);
  }
  int ans = 0, l = 0, r = 1e9, mid;
  while (l <= r) {
    mid = (l + r) / 2;
    for (int i = 1; i < n + 1; i++) {
      par[i] = i;
    }
    for (auto &e : a) {
      if (e.second == 0) {
        e.first = mid;
      }
    }
    sort(a, a + m);
    bool cs = false;
    int done = 0;
    for (auto e : a) {
      int u = ed[e.second].first, v = ed[e.second].second, w = e.first;
      if (p(u) != p(v)) {
        un(u, v);
        ++done;
        if (e.second == 0) {
          cs = true;
        }
      }
      if (done == n - 1) {
        break;
      }
    }
    if (cs) {
      ans = mid;
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  cout << ans;
}
