#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
struct node {
  int x, y, z;
} a[N];
int p[N];
bool cmp(node b, node c) { return b.z < c.z; }
int find(int x) { return x == p[x] ? x : p[x] = find(p[x]); }
int main() {
  int n, m, t = n - 1;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 0; i < m; i++) scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].z);
  sort(a + 1, a + m, cmp);
  for (int i = 1; i < m; i++) {
    if (find(a[i].x) != find(a[i].y)) {
      p[find(a[i].x)] = find(a[i].y);
      if (find(a[0].x) == find(a[0].y)) {
        printf("%d", a[i].z);
        return 0;
      }
    }
  }
  printf("1000000000");
}
