#include <bits/stdc++.h>
using namespace std;
char inline nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
template <typename T>
bool rd(T& v) {
  static char ch;
  while (ch != EOF && !isdigit(ch)) ch = nc();
  if (ch == EOF) return false;
  for (v = 0; isdigit(ch); ch = nc()) v = v * 10 + ch - '0';
  return true;
}
template <typename T>
void o(T p) {
  static int stk[70], tp;
  if (p == 0) {
    putchar('0');
    return;
  }
  if (p < 0) {
    p = -p;
    putchar('-');
  }
  while (p) stk[++tp] = p % 10, p /= 10;
  while (tp) putchar(stk[tp--] + '0');
}
const int maxn = 2e5 + 5;
const int maxm = 1e6 + 5;
const int inf = 1e9;
int fa[maxn];
int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); }
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, pair<int, int>>> edge(m);
  for (int i = 0; i < m; i++) {
    cin >> edge[i].second.first >> edge[i].second.second >> edge[i].first;
  }
  sort(edge.begin() + 1, edge.end());
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i < edge.size(); i++) {
    int x = edge[i].second.first, y = edge[i].second.second;
    int px = Find(x), py = Find(y);
    if (px != py) {
      int p1 = Find(edge[0].second.first), p2 = Find(edge[0].second.second);
      if (p1 == px && p2 == py) {
        cout << edge[i].first << endl;
        return 0;
      }
      if (p1 == py && p2 == px) {
        cout << edge[i].first << endl;
        return 0;
      }
      fa[px] = py;
    }
  }
  cout << (int)1e9 << endl;
}
