#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long md = 1000 * 1000 * 1000 + 7;
long long pw(long long a, long long b) {
  long long c = 1, m = a;
  while (b) {
    if (b & 1) c = (c * m) % md;
    m = (m * m) % md;
    b /= 2;
  }
  return c;
}
long long mul(long long a, long long b, long long c, long long d) {
  return (((((a * b) % md) * c) % md) * d) % md;
}
vector<int> parent(100005), size(100005);
int find(int x) {
  if (parent[x] == x) return x;
  if (parent[parent[x]] == parent[x]) return parent[x];
  return find(parent[parent[x]]);
}
void join(int x, int y) {
  if (size[x] > size[y]) {
    parent[y] = x;
    size[x] += size[y];
  } else {
    parent[x] = y;
    size[y] += size[x];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  int i, j, u, v, w, a, b, wt;
  vector<pair<int, pair<int, int>>> edges;
  cin >> a >> b >> wt;
  for (i = 1; i < m; ++i) {
    cin >> u >> v >> w;
    edges.push_back(make_pair(w, make_pair(u, v)));
  }
  sort(edges.begin(), edges.end());
  for (i = 1; i < 1 + n; ++i) parent[i] = i, size[i] = 1;
  for (auto y : edges) {
    w = y.first, u = y.second.first, v = y.second.second;
    u = find(u), v = find(v);
    if (u == v) continue;
    join(u, v);
    if (find(a) == find(b)) {
      cout << w;
      return 0;
    }
  }
  cout << 1000 * 1000 * 1000;
  return 0;
}
