#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int a = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) a = (a << 3) + (a << 1) + ch - '0';
  return a * f;
}
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
int n, m, fa[N], cnt;
struct edge {
  int to, from, val;
  inline bool operator<(const edge& a) const { return val < a.val; }
} e[N << 2];
int find(int x) {
  if (fa[x] == x) return x;
  return fa[x] = find(fa[x]);
}
signed main() {
  n = read(), m = read();
  for (int i = 1; i <= m; i++) {
    e[i].from = read();
    e[i].to = read();
    e[i].val = read();
  }
  for (int i = 1; i <= n; i++) fa[i] = i;
  sort(e + 2, e + m + 1);
  for (int i = 2; i <= m && cnt < n - 1; i++) {
    int x = e[i].from, y = e[i].to;
    if (find(x) == find(y)) continue;
    fa[find(x)] = find(y);
    cnt++;
    if (find(e[1].from) == find(e[1].to)) {
      printf("%d\n", e[i].val);
      return 0;
    }
  }
  if (cnt < n - 1) puts("1000000000");
  return 0;
}
