#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
int n, m;
vector<vector<pair<int, int>>> gr;
vector<int> dsu;
int root(int x) {
  if (dsu[x] == x) return x;
  return dsu[x] = root(dsu[x]);
}
void join(int x, int y) { dsu[root(x)] = root(y); }
bool mst(int a, int b, int c) {
  dsu.assign(n, 0);
  for (int i = 1; i < n; ++i) dsu[i] = i;
  priority_queue<pair<pair<int, bool>, pair<int, int>>> q;
  for (auto &i : gr[a]) q.push({{-i.second, 0}, {a, i.first}});
  q.push({{-c, 1}, {a, b}});
  while (!q.empty()) {
    int cc = -q.top().first.first, e = q.top().second.first,
        d = q.top().second.second;
    q.pop();
    if (cc > c) return 0;
    if (root(e) != root(d)) {
      if (cc == c && d == b) return 1;
      join(e, d);
      for (auto &i : gr[d]) q.push({{-i.second, 0}, {d, i.first}});
    }
  }
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  gr.assign(n, {});
  int a, b;
  scanf("%d%d%*d", &a, &b);
  --a, --b;
  while (--m) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    --x, --y;
    gr[x].push_back({y, z});
    gr[y].push_back({x, z});
  }
  int k = 0;
  const int m = 1e9;
  for (int i = m; i > 0; i >>= 1)
    while (k + i <= m && mst(a, b, k + i)) k += i;
  printf("%d\n", k);
}
