#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
constexpr auto MOD = 1000000007LL;
constexpr auto LINF = (1LL << 60);
constexpr auto INF = 1000000000LL;
constexpr auto PI = 3.1415926535897932384626433;
constexpr auto EPS = 1E-9;
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> p) {
  out << p.first << ' ' << p.second;
  return out;
}
template <typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
  in >> p.first >> p.second;
  return in;
}
template <typename T>
istream &operator>>(istream &in, vector<T> &v) {
  for (auto &x : v) in >> x;
  return in;
}
template <typename T>
ostream &operator<<(ostream &out, vector<T> v) {
  for (int i = 0; i < v.size(); i++)
    out << v[i] << (i + 1 == v.size() ? '\n' : ' ');
  out.flush();
  return out;
}
struct node {
  node *l, *r, *par;
  bool rev;
  int val, mx;
  node() { val = mx = 0; }
};
node T[100010 + 1000010];
inline void reverse(node *x) {
  if (x) {
    x->rev ^= 1;
    swap(x->l, x->r);
  }
  return;
}
void maintain(node *x) {
  if (x) {
    x->mx = x->val;
    if (x->l) {
      x->mx = max(x->mx, x->l->mx);
    }
    if (x->r) {
      x->mx = max(x->mx, x->r->mx);
    }
  }
  return;
}
inline bool isroot(node *x) {
  if (not x->par) return true;
  return x->par->l != x && x->par->r != x;
}
inline void push(node *x) {
  if (x) {
    if (x->rev) reverse(x->l), reverse(x->r);
    x->rev = false;
  }
  return;
}
inline void getpushed(node *x) {
  if (not isroot(x)) getpushed(x->par);
  push(x);
}
void rotate(node *x) {
  node *y = x->par;
  node *z = y->par;
  if (not isroot(y)) {
    if (z->l == y) z->l = x;
    if (z->r == y) z->r = x;
  }
  x->par = z;
  if (y->r == x) {
    if (y->r = x->l) y->r->par = y;
    y->par = x;
    x->l = y;
  } else {
    if (y->l = x->r) y->l->par = y;
    y->par = x;
    x->r = y;
  }
  maintain(y), maintain(x), maintain(z);
  return;
}
inline void splay(node *x) {
  getpushed(x);
  while (not isroot(x)) {
    node *y = x->par;
    if (not isroot(y)) {
      node *z = y->par;
      if ((z->l == y) ^ (y->l == x))
        rotate(x);
      else
        rotate(y);
    }
    rotate(x);
  }
  return;
}
inline node *access(node *x) {
  node *ret = NULL;
  while (x) {
    splay(x);
    x->r = ret;
    maintain(x);
    ret = x;
    x = x->par;
  }
  return ret;
}
inline void makeroot(node *x) {
  access(x);
  splay(x);
  reverse(x);
  return;
}
inline void link(node *x, node *y) {
  makeroot(x);
  x->par = y;
  return;
}
inline void cut(node *x, node *y) {
  makeroot(x);
  access(y);
  splay(y);
  y->l = NULL;
  x->par = NULL;
  return;
}
inline bool connected(node *x, node *y) {
  makeroot(x);
  access(y);
  splay(x);
  node *t = y;
  while (t->par) t = t->par;
  return t == x;
}
int n, m, res = 1e9;
pii a[1000010];
int w[1000010], ord[1000010];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> w[i];
    if (i > 0) {
      T[i + n].val = T[i + n].mx = w[i];
    }
    ord[i] = i;
  }
  sort(ord + 1, ord + m, [](int x, int y) { return w[x] < w[y]; });
  for (int i = 1; i < m; i++) {
    int j = ord[i];
    auto [u, v] = a[j];
    if (!connected(T + u, T + v)) {
      link(T + u, T + n + j);
      link(T + v, T + n + j);
    }
  }
  auto [u, v] = a[0];
  if (connected(T + u, T + v)) {
    makeroot(T + u);
    access(T + v);
    res = T[v].mx;
  }
  cout << res << endl;
  return 0;
}
