#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
struct node {
  int u, v, c;
  bool operator<(const node& rhs) const { return c < rhs.c; }
} edge[maxn];
int f[maxn];
int getf(int x) {
  if (x == f[x]) return x;
  return f[x] = getf(f[x]);
}
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) f[i] = i;
  for (int i = 0; i < m; i++) cin >> edge[i].u >> edge[i].v >> edge[i].c;
  sort(edge + 1, edge + m);
  int uu = edge[0].u, vv = edge[0].v;
  for (int i = 1; i < m; i++) {
    int u = edge[i].u, v = edge[i].v;
    int x = getf(u), y = getf(v);
    if (x != y) {
      f[x] = y;
      if (getf(uu) == getf(vv)) return 0 * printf("%d\n", edge[i].c);
    }
  }
  int k = 1e9;
  printf("%d\n", k);
  return 0;
}
