#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
const int M = 2e6 + 10;
inline int read() {
  register int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  return (f == 1) ? x : -x;
}
int n, m, q;
int p[N];
int find(int x) {
  if (x == p[x]) return x;
  return p[x] = find(p[x]);
}
struct lct {
  int ch[N][2], f[N], st[N];
  long long s[N], v[N];
  int mx[N];
  bool rev[N];
  bool nroot(int x) { return ch[f[x]][0] == x || ch[f[x]][1] == x; }
  void pushup(int x) {
    if (s[ch[x][1]] > s[ch[x][0]])
      mx[x] = mx[ch[x][1]];
    else
      mx[x] = mx[ch[x][0]];
    s[x] = max(s[ch[x][0]], s[ch[x][1]]);
    if (s[x] < v[x]) s[x] = v[x], mx[x] = x;
  }
  void pushr(int x) {
    swap(ch[x][0], ch[x][1]);
    rev[x] ^= 1;
  }
  void pushdown(int x) {
    if (rev[x]) {
      if (ch[x][0]) pushr(ch[x][0]);
      if (ch[x][1]) pushr(ch[x][1]);
      rev[x] = 0;
    }
  }
  void rotate(int x) {
    int y = f[x], z = f[y], k = ch[y][1] == x, w = ch[x][!k];
    if (nroot(y)) ch[z][ch[z][1] == y] = x;
    ch[x][!k] = y;
    ch[y][k] = w;
    if (w) f[w] = y;
    f[y] = x;
    f[x] = z;
    pushup(y);
  }
  void splay(int x) {
    int y = x, z = 0;
    st[++z] = y;
    while (nroot(y)) st[++z] = y = f[y];
    while (z) pushdown(st[z--]);
    while (nroot(x)) {
      y = f[x];
      z = f[y];
      if (nroot(y)) rotate((ch[y][0] == x) ^ (ch[z][0] == y) ? x : y);
      rotate(x);
    }
    pushup(x);
  }
  void access(int x) {
    for (int y = 0; x; x = f[y = x]) splay(x), ch[x][1] = y, pushup(x);
  }
  void makeroot(int x) {
    access(x);
    splay(x);
    pushr(x);
  }
  int findroot(int x) {
    access(x);
    splay(x);
    while (ch[x][0]) pushdown(x), x = ch[x][0];
    splay(x);
    return x;
  }
  void split(int x, int y) {
    makeroot(x);
    access(y);
    splay(y);
  }
  void link(int x, int y) {
    makeroot(x);
    if (findroot(y) != x) {
      f[x] = y;
    }
  }
  void cut(int x, int y) {
    split(x, y);
    ch[y][0] = f[x] = 0;
    pushup(y);
  }
  bool connect(int x, int y) { return findroot(x) == findroot(y); }
} lct;
struct edge {
  int l, r, w;
} e[M];
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 1; i <= m; i++) {
    e[i].l = read(), e[i].r = read(), e[i].w = read();
    lct.s[i + n] = lct.v[i + n] = e[i].w;
    lct.mx[i + n] = i + n;
  }
  for (int i = 2; i <= m; i++) {
    int x = find(e[i].l), y = find(e[i].r);
    if (x != y) {
      lct.link(i + n, e[i].l);
      lct.link(i + n, e[i].r);
      p[x] = y;
    } else {
      lct.split(e[i].l, e[i].r);
      if (lct.s[e[i].r] > e[i].w) {
        int t = lct.mx[e[i].r];
        lct.cut(t, e[t - n].l);
        lct.cut(t, e[t - n].r);
        lct.link(e[i].l, i + n);
        lct.link(e[i].r, i + n);
      }
    }
  }
  int x = find(e[1].l), y = find(e[1].r);
  if (x != y) {
    int t = 1e9;
    cout << t << '\n';
  } else {
    lct.split(e[1].l, e[1].r);
    cout << lct.s[e[1].r] << '\n';
  }
}
