#include <bits/stdc++.h>
using namespace std;
long long n, m, need, xx, yy, cnt = 0;
long long father[100005], maxv[100005], head[100005];
struct node {
  long long u, v, w, choose;
} a[1000005];
struct edge {
  long long next, to, dis;
} e[1000005];
void add_edge(long long u, long long v, long long w) {
  cnt++;
  e[cnt].to = v;
  e[cnt].dis = w;
  e[cnt].next = head[u];
  head[u] = cnt;
}
bool cmp(node xx, node yy) { return xx.w < yy.w; }
long long find(long long x) {
  if (x == father[x]) return x;
  return father[x] = find(father[x]);
}
void dfs(long long now, long long fath) {
  for (long long i = head[now]; i; i = e[i].next)
    if (e[i].to != fath)
      maxv[e[i].to] = max(maxv[now], e[i].dis), dfs(e[i].to, now);
}
signed main() {
  cin >> n >> m;
  need = n - 1;
  for (long long i = 1; i <= m; i++) cin >> a[i].u >> a[i].v >> a[i].w;
  sort(a + 2, a + m + 1, cmp);
  for (long long i = 1; i <= n; i++) father[i] = i;
  for (long long i = 2; i <= m; i++) {
    long long x = a[i].u, y = a[i].v;
    long long fx = find(x), fy = find(y);
    if (fx != fy) father[fx] = fy;
  }
  for (long long i = 1; i <= n; i++) {
    if (find(2) != find(i)) return cout << 1000000000 << endl, 0;
  }
  for (long long i = 1; i <= n; i++) father[i] = i;
  for (long long i = 2; i <= m; i++) {
    long long x = a[i].u, y = a[i].v;
    long long fx = find(x), fy = find(y);
    if (fx == fy) continue;
    a[i].choose = 1;
    father[fx] = fy;
    need--;
    if (!need) break;
  }
  for (long long i = 1; i <= m; i++)
    if (a[i].choose)
      add_edge(a[i].u, a[i].v, a[i].w), add_edge(a[i].v, a[i].u, a[i].w);
  xx = a[1].u, yy = a[1].v;
  dfs(xx, 0);
  cout << maxv[yy] << endl;
  return 0;
}
