#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
pair<long long int, pair<long long int, long long int> > edges[MAXN];
long long int N, M;
long long int parent[MAXN];
long long int find_root(long long int x) {
  while (x != parent[x]) {
    parent[x] = parent[parent[x]];
    x = parent[x];
  }
  return x;
}
void merge(long long int a, long long int b) {
  long long int pa = find_root(a);
  long long int push_back = find_root(b);
  if (pa != push_back) {
    parent[pa] = push_back;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> M;
  long long int X, Y, T, x, y, w;
  long long int ans = 1e9;
  cin >> X >> Y >> T;
  for (int i = 2; i <= M; i++) {
    cin >> x >> y >> w;
    edges[i] = make_pair(w, make_pair(x, y));
  }
  for (int i = 1; i <= N; i++) {
    parent[i] = i;
  }
  sort(edges + 2, edges + M + 1);
  for (int i = 2; i <= M; i++) {
    x = edges[i].second.first;
    y = edges[i].second.second;
    w = edges[i].first;
    merge(x, y);
    if (find_root(X) == find_root(Y)) {
      ans = w;
      break;
    }
  }
  cout << ans << endl;
}
