#include <bits/stdc++.h>
using namespace std;
int n, m, l, r, mid, ans, idx;
int fa[1000010], vis[1000010], temp[1000010];
struct node {
  int u, v, w, id;
} edge[1000010], edge2[1000010];
bool cmp(node a, node b) {
  if (a.w != b.w) return a.w < b.w;
  return a.id < b.id;
}
int find(int x) {
  if (x == fa[x]) return x;
  return fa[x] = find(fa[x]);
}
bool check(int x) {
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
  }
  for (int i = 1; i <= idx; i++) {
    edge2[i].id = edge[i].id;
    edge2[i].u = edge[i].u;
    edge2[i].v = edge[i].v;
    edge2[i].w = edge[i].w;
  }
  edge2[1].w = x;
  sort(edge2 + 1, edge2 + 1 + idx, cmp);
  for (int i = 1; i <= idx; i++) {
    int f1 = find(edge2[i].u);
    int f2 = find(edge2[i].v);
    if (f1 == f2) continue;
    fa[f2] = f1;
    vis[edge2[i].id] = 1;
  }
  if (vis[1] == 1)
    return 1;
  else
    return 0;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    edge[++idx].u = u;
    edge[idx].v = v;
    edge[idx].w = w;
    edge[idx].id = i;
  }
  l = 0, r = 1e9;
  while (l <= r) {
    vis[1] = 0;
    int mid = (l + r) >> 1;
    if (check(mid)) {
      ans = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  cout << ans;
  return 0;
}
