#include <bits/stdc++.h>
using namespace std;
template <class T>
void _R(T &x) {
  cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U>
void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 9;
struct Edge {
  int u, v, w;
  int id;
  int flag = 0;
} edge[maxn];
int fa[maxn];
int find(int x) {
  if (fa[x] == x) return x;
  return fa[x] = find(fa[x]);
}
bool cmp(Edge a, Edge b) {
  if (a.w == b.w) return a.id < b.id;
  return a.w < b.w;
}
int n, m;
bool check(int val) {
  for (int i = 1; i <= m; i++) {
    if (edge[i].id == 1) {
      edge[i].w = val;
      break;
    }
  }
  for (int i = 1; i <= n; i++) fa[i] = i;
  sort(edge + 1, edge + 1 + m, cmp);
  for (int i = 1; i <= m; i++) {
    int fu = find(edge[i].u);
    int fv = find(edge[i].v);
    if (fu == fv) continue;
    fa[fu] = fv;
    if (edge[i].id == 1) return true;
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &edge[i].u, &edge[i].v, &edge[i].w);
    edge[i].id = i;
  }
  int res, le = 0, ri = 1000000000;
  while (le <= ri) {
    int mid = (le + ri) >> 1;
    if (check(mid))
      le = mid + 1, res = mid;
    else
      ri = mid - 1;
  }
  printf("%d\n", res);
  return 0;
}
