#include <bits/stdc++.h>
using namespace std;
struct edge {
  int a, b;
  long long w;
};
int n, m;
vector<edge> edges;
int par[100005];
edge one;
int findPar(int curr) {
  if (par[curr] != curr) par[curr] = findPar(par[curr]);
  return par[curr];
}
bool compare(const edge& a, const edge& b) { return a.w < b.w; }
bool inSpTree(long long mid) {
  for (int i = 0; i < n; i++) par[i] = i;
  int count = 0, i = 1;
  while (count < n - 1 && i <= m) {
    if (i == m || edges[i].w >= mid) {
      if (findPar(one.a) != findPar(one.b)) return true;
      return false;
    }
    int source = findPar(edges[i].a), dest = findPar(edges[i].b);
    if (source != dest) {
      par[source] = dest;
      count++;
    }
    i++;
  }
  return false;
}
int main() {
  long long l = 0, r = 1e9;
  cin >> n >> m;
  edges = vector<edge>(m);
  long long a, b, e;
  edge add;
  cin >> a >> b >> e;
  one.a = --a, one.b = --b, one.w = -1;
  edges[0] = one;
  for (int i = 1; i < m; ++i) {
    cin >> a >> b >> e;
    add.a = --a, add.b = --b, add.w = e;
    edges[i] = add;
  }
  sort(edges.begin(), edges.end(), compare);
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (inSpTree(mid)) {
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  cout << r << endl;
  return 0;
}
