#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, m;
int st, ed;
struct NODE {
  int u, v, w;
} a[N];
bool cmp(NODE& p, NODE& q) { return p.w < q.w; }
int fa[N];
int getfa(int u) {
  if (fa[u] == u)
    return u;
  else
    return fa[u] = getfa(fa[u]);
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= n; i++) fa[i] = i;
    for (int i = 0; i < m; i++) {
      scanf("%d%d%d", &a[i].u, &a[i].v, &a[i].w);
      if (i == 0) st = a[i].u, ed = a[i].v;
    }
    sort(a + 1, a + m, cmp);
    int ans = 1000000000;
    for (int i = 1; i < m; i++) {
      int u = a[i].u, v = a[i].v;
      int fu = getfa(u), fv = getfa(v);
      if (fu == fv) continue;
      fa[fu] = fv;
      if (getfa(st) == getfa(ed)) {
        ans = a[i].w;
        break;
      }
    }
    printf("%d\n", ans);
  }
}
