#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX = 1e6;
const int MAXN = 1e5;
const ll oo = 1e9;
set<pair<int, int>> edges;
int n, m, u[MAX + 1], v[MAX + 1];
class DSU {
 private:
  int p[MAXN + 1];
  int sz[MAXN + 1];

 public:
  DSU() {
    for (int i = 0; i <= MAXN; ++i) {
      p[i] = i;
      sz[i] = 1;
    }
  }
  DSU(int n) { init(n); }
  void init(int n) {
    for (int i = 0; i <= n; ++i) {
      p[i] = i;
      sz[i] = 1;
    }
  }
  int find(int a) {
    while (a != p[a]) {
      return (p[a] = find(p[a]));
    }
    return a;
  }
  void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if (sz[a] < sz[b]) swap(a, b);
    sz[a] += sz[b];
    p[b] = a;
  }
  bool same(int a, int b) { return (find(a) == find(b)); }
};
bool find_mst(int w, DSU &dsu) {
  pair<int, int> c1 = {w, 1};
  dsu.init(n);
  edges.insert(c1);
  for (auto [w, num] : edges) {
    if (!dsu.same(u[num], v[num])) {
      dsu.unite(u[num], v[num]);
      if (num == 1) {
        edges.erase(edges.find(c1));
        return true;
      }
    }
  }
  edges.erase(c1);
  return false;
}
void solve() {
  DSU dsu;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int a, b, w;
    cin >> a >> b >> w;
    u[i] = a;
    v[i] = b;
    if (i != 1) edges.insert({w, i});
  }
  int l = 0, r = 1e9;
  int ans = 0;
  while (l <= r) {
    ll m = l + (r - l) / 2;
    if (find_mst(m, dsu)) {
      ans = m;
      l = m + 1;
    } else {
      r = m - 1;
    }
  }
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
