#include <bits/stdc++.h>
using namespace std;
int n, m, p, q, cnt, ans, fa[100010];
bool pi[10 * 100010];
int ff(int a) {
  if (fa[a] == a) return a;
  return fa[a] = ff(fa[a]);
}
struct node {
  int a, b, w;
  bool operator<(node const &a) const { return w < a.w; }
} e[10 * 100010];
int main() {
  int i, s, a, b, j, k;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) scanf("%d%d%d", &e[i].a, &e[i].b, &e[i].w);
  sort(e + 2, e + 1 + m);
  for (i = 1; i <= n; i++) fa[i] = i;
  fa[e[1].a] = fa[e[1].b];
  for (i = 2; i <= m; i++) {
    a = ff(e[i].a);
    b = ff(e[i].b);
    if (a != b) {
      pi[i] = 1;
      fa[a] = b;
    }
  }
  for (i = 1; i <= n; i++) fa[i] = i;
  for (i = 2; i <= m; i++)
    if (pi[i]) {
      a = ff(e[i].a);
      b = ff(e[i].b);
      fa[a] = b;
    }
  ans = 1e9;
  for (i = 2; i <= m; i++)
    if (!pi[i]) {
      a = ff(e[i].a);
      b = ff(e[i].b);
      if (a != b) ans = min(ans, e[i].w);
    }
  printf("%d", ans);
  return 0;
}
