#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
struct ano {
  int c, d, id;
  bool operator<(const ano &x) const {
    if (d == x.d) return id > x.id;
    return d > x.d;
  }
};
vector<vector<ano> > a(N);
unordered_map<int, bool> v;
priority_queue<ano> q;
int xx, yy;
bool chk(int &w) {
  a[xx][0].d = w;
  a[yy][0].d = w;
  while (!q.empty()) q.pop();
  q.push({xx, 0, 0});
  v.clear();
  while (!q.empty()) {
    if (v[q.top().c]) {
      q.pop();
    } else {
      ano temp = q.top();
      q.pop();
      if (temp.id == 1) return true;
      if (temp.c == yy) return false;
      v[temp.c] = true;
      for (auto &x : a[temp.c]) {
        if (!v[x.c]) q.push(x);
      }
    }
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  int i;
  int x, y, w, dist[m + 1];
  cin >> x >> y >> w;
  xx = x;
  yy = y;
  a[x].push_back({y, w, 1});
  a[y].push_back({x, w, 1});
  dist[0] = w;
  for (i = 2; i <= m; i++) {
    cin >> x >> y >> w;
    a[x].push_back({y, w, i});
    a[y].push_back({x, w, i});
    dist[i - 1] = w;
  }
  dist[m] = 1e9;
  sort(dist, dist + m + 1);
  int l = 0, mid, r = m;
  bool ok;
  int ans;
  while (l <= r) {
    mid = (l + r) / 2;
    ok = chk(dist[mid]);
    if (ok) {
      l = mid + 1;
      ans = dist[mid];
    } else
      r = mid - 1;
  }
  assert(l > 0);
  cout << ans;
}
