#include <bits/stdc++.h>
using namespace std;
const int maxp = 22;
const long double EPS = 1e-18;
const long long INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 2e5 + 1;
struct DSU {
  vector<int> par, siz;
  int cnt;
  void init(int n) {
    cnt = n;
    par.assign(n + 1, 0);
    siz.assign(n + 1, 1);
    iota(par.begin(), par.end(), 0);
  }
  int find(int x) { return (par[x] == x) ? x : par[x] = find(par[x]); }
  bool merge(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    cnt--;
    return true;
  }
};
struct edge {
  int x, y, z;
  bool operator<(const edge &a) const { return z < a.z; }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  int i;
  edge edges[m - 1];
  int x, y, a;
  cin >> x >> y >> a;
  for (i = 0; i < m - 1; i++) cin >> edges[i].x >> edges[i].y >> edges[i].z;
  sort(edges, edges + m - 1);
  DSU dsu;
  dsu.init(n);
  int ans = 1e9;
  for (i = 0; i < m - 1; i++) {
    dsu.merge(edges[i].x, edges[i].y);
    x = dsu.find(x);
    y = dsu.find(y);
    if (x == y) {
      ans = edges[i].z;
      break;
    }
  }
  cout << ans;
}
