#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > V;
int R[100007];
int roz[100007];
pair<int, pair<int, int> > t[1000007];
int Find(int x) {
  if (R[x] != x) R[x] = Find(R[x]);
  return R[x];
}
void Union(int a, int b) {
  a = Find(a);
  b = Find(b);
  if (roz[b] > roz[a]) swap(a, b);
  R[b] = a;
  roz[a] += roz[b];
}
int DFS(int x, int r, int y) {
  int p = 0;
  for (int i = 0; i < V[x].size(); i++) {
    if (V[x][i].first == y) {
      return V[x][i].second;
    }
    if (V[x][i].first != r) {
      p = DFS(V[x][i].first, x, y);
      if (p != 0) {
        return max(p, V[x][i].second);
      }
    }
  }
  return p;
}
int main(void) {
  int n, m, a, b, c, d, x, y, z;
  scanf("%d %d", &n, &m);
  V.resize(n + 7);
  for (int i = 1; i <= n; i++) {
    R[i] = i;
    roz[i] = 1;
  }
  scanf("%d %d %d", &a, &b, &c);
  for (int i = 2; i <= m; i++) {
    scanf("%d %d %d", &x, &y, &z);
    t[i - 2] = {z, {x, y}};
  }
  sort(t, t + m - 1);
  int odp = 0;
  for (int i = 0; i < m - 1; i++) {
    z = t[i].first;
    x = t[i].second.first;
    y = t[i].second.second;
    if (Find(x) != Find(y)) {
      Union(x, y);
      V[x].push_back({y, z});
      V[y].push_back({x, z});
    }
    if (Find(a) == Find(b)) {
      odp = z;
      break;
    }
  }
  if (Find(a) != Find(b)) odp = 1e9;
  printf("%d", odp);
  return 0;
}
