#include <bits/stdc++.h>
using namespace std;
int f[100050];
int n, m;
int getf(int x) {
  if (x == f[x]) return x;
  return f[x] = getf(f[x]);
}
struct node {
  int u, v, c, id;
  bool operator<(const node& rhs) const {
    if (c == rhs.c) return id < rhs.id;
    return c < rhs.c;
  }
} node[100050 * 10], temp[100050 * 10];
bool judge(int x) {
  for (int i = 1; i <= n; i++) f[i] = i;
  int cnt = 0;
  node[0].c = x;
  int flag = 0;
  for (int i = 1; i < m; i++) {
    if (flag == 0 && node[0].c <= node[i].c) {
      temp[cnt].id = node[0].id;
      temp[cnt].c = node[0].c;
      temp[cnt].u = node[0].u;
      temp[cnt++].v = node[0].v;
      flag = 1;
    }
    temp[cnt].id = node[i].id;
    temp[cnt].c = node[i].c;
    temp[cnt].u = node[i].u;
    temp[cnt++].v = node[i].v;
  }
  if (cnt != m) {
    temp[cnt].id = node[0].id;
    temp[cnt].c = node[0].c;
    temp[cnt].u = node[0].u;
    temp[cnt++].v = node[0].v;
  }
  for (int i = 0; i < cnt; i++) {
    int u = temp[i].u;
    int v = temp[i].v;
    int x = getf(u), y = getf(v);
    if (x != y) {
      if (temp[i].id == 0) return true;
      f[x] = y;
    }
  }
  return false;
}
int main() {
  cin >> n >> m;
  int cnt = 0;
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &node[cnt].u, &node[cnt].v, &node[cnt].c);
    node[cnt].id = i;
    if (node[cnt].u != node[cnt].v) cnt++;
  }
  m = cnt;
  sort(node + 1, node + m);
  int l = 0, r = 1e9, ans;
  while (l < r) {
    int mid = (l + r) / 2;
    if (judge(mid)) {
      l = mid + 1;
      ans = mid;
    } else
      r = mid - 1;
  }
  if (l == r && judge(l)) ans = l;
  printf("%d\n", ans);
  return 0;
}
