#include <bits/stdc++.h>
using namespace std;
int p[200000];
int n, m;
vector<pair<pair<int, int>, pair<int, int> > > e;
int par(int u) {
  if (u == p[u]) return u;
  p[u] = par(p[u]);
  return p[u];
}
bool pos(int t) {
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 0; i < m; i++) {
    if (e[i].first.second == 0) e[i].first.first = t;
  }
  sort(e.begin(), e.end());
  for (int i = 0; i < m; i++) {
    int u, v, w, id;
    w = e[i].first.first;
    id = e[i].first.second;
    u = e[i].second.first;
    v = e[i].second.second;
    u = par(u);
    v = par(v);
    if (id == 0) {
      if (u == v)
        return false;
      else
        return true;
    } else
      p[v] = u;
  }
}
int main() {
  int u, v, w;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &u, &v, &w);
    e.push_back({{w, i}, {u, v}});
  }
  int l = 0;
  int r = 1000000000;
  int mid;
  while (l < r) {
    mid = (l + r + 1) >> 1;
    if (pos(mid))
      l = mid;
    else
      r = mid - 1;
  }
  printf("%d", l);
  return 0;
}
