#include <bits/stdc++.h>
using namespace std;
int union_tree[200000];
int union_find(int now) {
  if (union_tree[now] == now) return now;
  return union_tree[now] = union_find(union_tree[now]);
}
int union_merge(int a, int b) {
  a = union_find(a);
  b = union_find(b);
  union_tree[a] = b;
  return 0;
}
vector<tuple<int, int, int>> edges;
int main() {
  int n, m;
  cin >> n >> m;
  pair<int, int> now;
  for (long long i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    if (i != 0) {
      edges.push_back(make_tuple(c, a, b));
    } else {
      now = make_pair(a, b);
    }
  }
  sort(edges.begin(), edges.end());
  edges.push_back(make_tuple(1e9, now.first, now.second));
  for (int q = 1; q <= n; ++q) {
    union_tree[q] = q;
  }
  for (int i = 0; i < edges.size(); ++i) {
    union_merge(get<1>(edges[i]), get<2>(edges[i]));
    if (union_find(now.first) == union_find(now.second)) {
      cout << get<0>(edges[i]) << endl;
      return 0;
    }
  }
}
