#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int id[N];
vector<pair<int, pair<int, int>>> vv;
int pos, f = 0;
int xx, yy;
map<int, int> mm;
void initialize() {
  for (int i = 1; i < N; ++i) id[i] = i;
}
int root(int x) {
  while (id[x] != x) {
    id[x] = id[id[x]];
    x = id[x];
  }
  return x;
}
void union1(int x, int y) {
  int p = root(x);
  int q = root(y);
  id[p] = id[q];
}
long long kruskal(vector<pair<int, pair<int, int>>> p) {
  int x, y;
  long long cost, minimumCost = 0;
  for (int i = 0; i < int(p.size()); ++i) {
    x = p[i].second.first;
    y = p[i].second.second;
    if (x == -1) x = xx;
    if (y == -1) y = yy;
    cost = p[i].first;
    if (root(x) != root(y)) {
      minimumCost += cost;
      union1(x, y);
      if ((x == xx && y == yy) || (x == yy && y == xx)) f = 1;
    }
  }
  return minimumCost;
}
bool bs(int ww) {
  vv[0].first = ww;
  vv[0].second.second = -1, vv[0].second.first = -1;
  sort(begin(vv), end(vv));
  f = 0;
  kruskal(vv);
  if (f == 1) return true;
  return false;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<int, pair<int, int>>> v;
  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    if (i == 0) {
      xx = x, yy = y;
    }
    v.push_back({z, {x, y}});
  }
  int l = 0, h = 1e9, ans = 0;
  int mid;
  vv = v;
  while (l <= h) {
    initialize();
    mid = (l + h) / 2;
    vv = v;
    if (bs(mid)) {
      ans = mid;
      l = mid + 1;
    } else {
      h = mid - 1;
    }
  }
  cout << ans;
}
