#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1E5 + 10;
const int MAXM = 1E6 + 10;
struct T {
  int u, v, w;
  bool operator<(const T &rhs) const { return w < rhs.w; }
} E[MAXM];
int n, m, fa[MAXN];
vector<pair<int, int> > T[MAXN];
multiset<int> S;
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void dfs(int x, int fa, int ed) {
  if (x == ed) throw 0;
  for (auto e : T[x])
    if (e.first != fa)
      S.insert(e.second), dfs(e.first, x, ed), S.erase(S.find(e.second));
}
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", &E[i].u, &E[i].v, &E[i].w);
  sort(E + 2, E + m + 1);
  int tot = 0;
  for (int i = 2; i <= m; i++)
    if (find(E[i].u) != find(E[i].v)) {
      ++tot;
      fa[find(E[i].u)] = find(E[i].v);
      T[E[i].u].emplace_back(E[i].v, E[i].w);
      T[E[i].v].emplace_back(E[i].u, E[i].w);
    }
  if (tot != n - 1) return puts("1000000000"), 0;
  try {
    dfs(E[1].u, 0, E[1].v);
  } catch (int ppp) {
  }
  printf("%d\n", *S.rbegin());
}
