#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, T b) {
  return b < a ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, T b) {
  return b > a ? a = b, 1 : 0;
}
inline int read() {
  int x(0), sgn(1);
  char ch(getchar());
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') sgn = -1;
  for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
  return x * sgn;
}
void File() {}
const int N = 1e5 + 1e3, M = 1e6 + 1e3;
int n, m;
struct Edge {
  int u, v, w;
} E[M];
vector<pair<int, int> > G[N];
int fa[N], S, T, ans;
int find(int x) { return fa[x] == x ? x : (fa[x] = find(fa[x])); }
bool Dfs(int u, int fa) {
  if (u == T) return true;
  for (auto it : G[u]) {
    int v = it.first, w = it.second;
    if (v == fa) continue;
    if (Dfs(v, u)) return chkmax(ans, w), true;
  }
  return false;
}
int main() {
  File();
  n = read();
  m = read();
  for (register int i = (1), iend = int(m); i <= iend; ++i) {
    int u = read(), v = read(), w = read();
    E[i] = (Edge){u, v, w};
  }
  sort(E + 2, E + m + 1, [&](Edge a, Edge b) { return a.w < b.w; });
  int tot = 0;
  for (register int i = (1), iend = int(n); i <= iend; ++i) fa[i] = i;
  for (register int i = (2), iend = int(m); i <= iend; ++i) {
    int u = E[i].u, v = E[i].v, w = E[i].w;
    if (find(u) != find(v)) {
      fa[find(u)] = find(v);
      ++tot;
      G[u].emplace_back(v, w);
      G[v].emplace_back(u, w);
    }
  }
  if (tot < n - 1) return printf("%d\n", int(1e9)), 0;
  S = E[1].u, T = E[1].v;
  Dfs(S, 0);
  printf("%d\n", ans);
  return 0;
}
