#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m, parent[N], sz[N];
vector<pair<pair<int, int>, pair<int, int>>> dummy;
int root(int v) {
  if (parent[v] != v) parent[v] = root(parent[v]);
  return parent[v];
}
void Union(int u, int v) {
  if (sz[u] < sz[v]) swap(u, v);
  parent[v] = u;
  sz[u] += sz[v];
  return;
}
bool func(int wt) {
  for (int i = 1; i < N; i++) parent[i] = i, sz[i] = 1;
  bool flag = false;
  vector<pair<pair<int, int>, pair<int, int>>> edge;
  edge.push_back({{wt, 0}, {dummy[0].second.first, dummy[0].second.second}});
  for (int i = 1; i < dummy.size(); i++)
    edge.push_back({{dummy[i].first.first, dummy[i].first.second},
                    {dummy[i].second.first, dummy[i].second.second}});
  sort(edge.begin(), edge.end());
  for (int it = 0; it < edge.size(); it++) {
    int x = edge[it].second.first;
    int y = edge[it].second.second;
    int w = edge[it].first.first;
    int num = edge[it].first.second;
    int rx = root(x);
    int ry = root(y);
    if (rx != ry) {
      if (!num) flag = true;
      Union(rx, ry);
    }
  }
  return flag;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y, w;
    cin >> x >> y >> w;
    dummy.push_back({{w, i}, {x, y}});
  }
  int ans = 0;
  int low = 0, high = 1e9;
  while (low <= high) {
    int mid = (low + high) / 2;
    if (func(mid)) {
      ans = mid;
      low = mid + 1;
    } else
      high = mid - 1;
  }
  cout << ans << "\n";
  return 0;
}
