#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
int p[101000];
int n, m;
int get(int v) {
  if (p[v] == v) return v;
  return p[v] = get(p[v]);
}
void unite(int a, int b) {
  a = get(a);
  b = get(b);
  if (rand() % 2) swap(a, b);
  p[a] = b;
}
struct edge {
  int x, y, w, ind;
};
bool cmp(edge a, edge b) {
  if (a.w == b.w) return a.ind < b.ind;
  return a.w < b.w;
}
bool solve(vector<edge>& a, int w) {
  for (edge& i : a) {
    if (i.ind == 1) {
      i.w = w;
      break;
    }
  }
  sort(a.begin(), a.end(), cmp);
  int cnt = n;
  bool chk = false;
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 0; i < m && cnt > 1; i++) {
    int x = a[i].x, y = a[i].y;
    if (get(x) == get(y)) continue;
    unite(x, y);
    cnt--;
    if (a[i].ind == 1) chk = true;
  }
  return chk;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  vector<edge> a(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i].x >> a[i].y >> a[i].w;
    a[i].ind = i + 1;
  }
  int l = 0, r = 1e9;
  while (l < r) {
    int m = (l + r + 1) / 2;
    if (solve(a, m))
      l = m;
    else
      r = m - 1;
  }
  cout << l << endl;
  return 0;
}
