#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, M = 1e6 + 10;
struct node {
  int a, b, w;
} e[M];
int fa[N];
bool cmp(node a, node b) { return a.w < b.w; }
int find(int x) {
  if (fa[x] != x) fa[x] = find(fa[x]);
  return fa[x];
}
int du[N];
int main() {
  int n, m;
  cin >> n >> m;
  int a1, b1, w1;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &e[i].a, &e[i].b, &e[i].w);
    if (i == 1) {
      a1 = e[i].a;
      b1 = e[i].b;
    }
  }
  for (int i = 1; i <= n; ++i) fa[i] = i;
  sort(e + 2, e + 1 + m, cmp);
  for (int i = 2; i <= m; ++i) {
    int f1 = find(e[i].a);
    int f2 = find(e[i].b);
    if (f1 == f2) continue;
    fa[f1] = f2;
    if (find(a1) == find(b1)) {
      printf("%d\n", e[i].w);
      return 0;
    }
  }
  printf("1000000000\n");
}
