#include <bits/stdc++.h>
using namespace std;
const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int MAX = 2 * 1000 * 1000 + 10;
const long long INF = 1e18;
const int MOD = 1e9 + 7;
vector<pair<long long, pair<long long, long long> > > v;
long long x, y, z;
long long par[MAX], siz[MAX];
void make() {
  for (long long i = 0; i < MAX; i++) {
    par[i] = i;
    siz[i] = 1;
  }
}
long long parent(long long x) {
  if (x == par[x]) return x;
  return par[x] = parent(par[x]);
}
void join(long long a, long long b) {
  a = parent(a);
  b = parent(b);
  if (a == b) return;
  if (siz[a] < siz[b]) swap(a, b);
  par[b] = a;
  siz[a] += siz[b];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m;
  cin >> n >> m;
  make();
  long long fu, fv, fc;
  cin >> fu >> fv >> fc;
  m--;
  for (long long i = 0; i < m; i++) {
    cin >> x >> y >> z;
    v.push_back(make_pair(z, make_pair(x, y)));
  }
  sort(v.begin(), v.end());
  long long ans = -1;
  for (auto i : v) {
    long long px = parent(i.second.first);
    long long py = parent(i.second.second);
    if (px == py) continue;
    long long pfu = parent(fu);
    long long pfv = parent(fv);
    if ((pfu == px and pfv == py) or (pfu == py and pfv == px)) {
      ans = i.first;
    }
    join(i.second.first, i.second.second);
  }
  if (parent(fu) != parent(fv)) {
    cout << (long long)1e9 << '\n';
  } else {
    cout << ans << '\n';
  }
}
