#include <bits/stdc++.h>
using namespace std;
inline int rd() {
  char ch = getchar();
  int s = 0, c = 1;
  while (!isdigit(ch)) {
    if (ch == '-') c = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    s = (s << 3) + (s << 1) + (ch ^ 48);
    ch = getchar();
  }
  return s * c;
}
int n, m;
struct node {
  int u, v, w;
} e[1000050];
int f[100050];
int fth(int x) { return f[x] == x ? x : f[x] = fth(f[x]); }
int u1, v1;
bool cmp(node x, node y) {
  if (x.w == y.w) {
    if (x.u == u1 && x.v == v1) return 1;
    return 0;
  }
  return x.w < y.w;
}
int main() {
  n = rd();
  m = rd();
  int i;
  for (i = 1; i <= m; ++i) e[i].u = rd(), e[i].v = rd(), e[i].w = rd();
  u1 = e[1].u, v1 = e[1].v;
  int l = 0, r = 1e9, mid;
  while (l < r) {
    for (i = 1; i <= n; ++i) f[i] = i;
    bool jb = 0;
    mid = l + r + 1 >> 1;
    for (i = 1; i <= m; ++i)
      if (e[i].u == u1 && e[i].v == v1) {
        e[i].w = mid;
      }
    sort(e + 1, e + 1 + m, cmp);
    int mxx = 0, u, v, fu, fv;
    for (i = 1; i <= m; ++i) {
      u = e[i].u, v = e[i].v;
      fu = fth(u), fv = fth(v);
      if (fu != fv) {
        f[fu] = fv;
        if (u == u1 && v == v1) jb = 1;
        mxx = max(mxx, e[i].w);
      }
    }
    if (jb)
      l = mid;
    else
      r = mid - 1;
  }
  cout << l;
  return 0;
}
