#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, z, up[100005], a, b, fp = 1e9;
set<pair<int, pair<int, int> > > s;
int upp(int dg) { return up[dg] == dg ? dg : up[dg] = upp(up[dg]); }
void un(int a, int b) { up[upp(a)] = upp(b); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) up[i] = i;
  for (int i = 1; i <= m; ++i) {
    cin >> x >> y >> z;
    if (i == 1)
      a = x, b = y;
    else
      s.insert({z, {x, y}});
  }
  while (s.size()) {
    un((*s.begin()).second.first, (*s.begin()).second.second);
    if (upp(a) == upp(b)) {
      fp = (*s.begin()).first;
      break;
    }
    s.erase(s.begin());
  }
  cout << fp << endl;
  return 0;
}
