#include <bits/stdc++.h>
using namespace std;
int rt[100005];
int find_rt(int first) {
  if (rt[first] == first) return first;
  return rt[first] = find_rt(rt[first]);
}
int n, m;
int s, t, w;
vector<pair<int, int> > v[100005];
vector<pair<int, pair<int, int> > > vec;
int mx[100005];
void dfs(int k, int pa, int w) {
  mx[k] = max(mx[pa], w);
  for (auto first : v[k]) {
    if (first.first == pa) continue;
    dfs(first.first, k, first.second);
  }
  return;
}
int main() {
  scanf("%d %d", &n, &m);
  scanf("%d %d %d", &s, &t, &w);
  int eg = 0;
  for (int i = 1; i <= n; i++) rt[i] = i;
  for (int i = 2; i <= m; i++) {
    int first, second, z;
    scanf("%d %d %d", &first, &second, &z);
    vec.push_back(pair<int, pair<int, int> >(z, pair<int, int>(first, second)));
  }
  sort(vec.begin(), vec.end());
  for (auto t : vec) {
    int first, second, z;
    z = t.first, first = t.second.first, second = t.second.second;
    int rx = find_rt(first), ry = find_rt(second);
    if (rx == ry) continue;
    rt[rx] = ry;
    eg++;
    v[first].push_back(pair<int, int>(second, z));
    v[second].push_back(pair<int, int>(first, z));
  }
  if (eg == n - 1) {
    dfs(s, 0, 0);
    printf("%d\n", mx[t]);
  } else
    puts("1000000000");
  return 0;
}
