#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m;
struct Edge {
  int x, y, w;
  friend bool operator<(Edge a, Edge b) { return a.w < b.w; }
} e[N * 10];
inline int read() {
  int x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x;
}
int fa[N];
int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); }
bool chk(int x) {
  for (int i = 0; i <= n; i++) fa[i] = i;
  for (int i = 2; i <= m; i++) {
    if (e[i].w < x) {
      int p = getfa(e[i].x), q = getfa(e[i].y);
      fa[p] = q;
    } else
      break;
  }
  return (getfa(e[1].x) != getfa(e[1].y));
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++)
    e[i].x = read(), e[i].y = read(), e[i].w = read();
  sort(e + 2, e + m + 1);
  int l = 0, r = 1e9, mid, ans = 0;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (chk(mid))
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%d\n", ans);
  return 0;
}
