#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while ((c = getchar()) == ' ')
    ;
  x = c;
}
inline void writes(string s) { puts(s.c_str()); }
inline void writeln() { writes(""); }
inline void writei(int x) {
  if (x < 0) {
    putchar('-');
    x = abs(x);
  }
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
inline void writell(long long x) {
  if (x < 0) {
    putchar('-');
    x = abs(x);
  }
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
int n, m, i, j, fa[100005], l, r, mid, ans;
struct edg {
  int x, y, z, id;
} a[1000005], b[1000005];
bool cmp(edg x, edg y) {
  if (x.z == y.z) return x.id < y.id;
  return x.z < y.z;
}
int fnd(int x) {
  if (fa[x] == x) return x;
  return fa[x] = fnd(fa[x]);
}
bool check(int x) {
  int i;
  for (((i)) = (1); ((i)) <= ((m)); ((i))++) b[i] = a[i];
  b[1].z = x;
  sort(b + 1, b + m + 1, cmp);
  for (((i)) = (1); ((i)) <= ((n)); ((i))++) fa[i] = i;
  for (((i)) = (1); ((i)) <= ((m)); ((i))++) {
    if (fnd(b[i].x) != fnd(b[i].y)) {
      fa[fnd(b[i].x)] = fnd(b[i].y);
      if (b[i].id == 1) return 1;
    }
  }
  return 0;
}
int main() {
  read(n);
  read(m);
  for (((i)) = (1); ((i)) <= ((m)); ((i))++) {
    read(a[i].x);
    read(a[i].y);
    read(a[i].z);
    a[i].id = i;
  }
  l = 0;
  r = 1e9 + 1;
  while (l < r) {
    int mid = (l + r) / 2;
    if (check(mid)) {
      l = mid + 1;
      ans = mid;
    } else
      r = mid;
  }
  cout << ans << endl;
  return 0;
}
