#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, int> a, pair<int, int> b) {
  return (a.first == b.first) ? a.second > b.second : a.first < b.first;
}
long long int modInverse(long long int a, long long int mod) {
  long long int m = mod;
  long long int y = 0, x = 1;
  while (a > 1) {
    long long int q = a / m;
    long long int t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += mod;
  return x;
}
long long int binpow(long long int a, long long int p) {
  if (p == 0) return 1;
  long long int ret = binpow(a, p / 2);
  ret *= ret;
  ret %= 1000000007;
  if (p % 2) {
    ret *= a;
    ret %= 1000000007;
  }
  return ret;
}
bool com(pair<int, int> a, pair<int, int> b) { return a.first >= b.first; }
const int N = 1e6 + 7;
int cyc_start = -1, cyc_end = -1;
long long int n, m, l, b, tar;
int s, t;
set<int> s1, s2;
int timer;
set<int> used;
vector<int> v1, v2, odd, even;
vector<int> color(N, -1);
int cyc;
int dx[8] = {0, 0, -1, 1, -1, -1, 1, 1};
int dy[8] = {-1, 1, 0, 0, 1, -1, 1, -1};
bool isValid(int i, int j) { return (i >= 0 && i < n && j >= 0 && j < m); }
vector<int> parent, rnk;
void make_set(int v) {
  parent[v] = v;
  rnk[v] = 0;
}
int find_set(int v) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v]);
}
void union_sets(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (rnk[a] < rnk[b]) swap(a, b);
    parent[b] = a;
    if (rnk[a] == rnk[b]) rnk[a]++;
  }
}
struct Edge {
  int u, v, in, weight;
};
vector<Edge> edges(N), edg(N);
bool mycomp(Edge e1, Edge e2) {
  if (e1.weight == e2.weight) return e1.in < e2.in;
  return e1.weight < e2.weight;
}
bool krskl(int s, int t) {
  for (int i = 0; i < m; i++) {
    edg[i] = edges[i];
  }
  for (int i = 0; i < n; i++) make_set(i);
  bool flag = 0;
  sort(edg.begin(), edg.begin() + m, mycomp);
  for (int i = 0; i < m; i++) {
    Edge e = edg[i];
    if (find_set(e.u) != find_set(e.v)) {
      if (e.u == s && e.v == t) flag = 1;
      union_sets(e.u, e.v);
    }
  }
  return flag;
}
void solve(int tc) {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> edges[i].u >> edges[i].v >> edges[i].weight;
    edges[i].in = i;
    edges[i].u--;
    edges[i].v--;
  }
  s = edges[0].u;
  t = edges[0].v;
  parent.resize(n + 1);
  rnk.resize(n + 1);
  int l = 0, r = 1e9, ans = 0;
  while (l <= r) {
    int mid = l + (r - l) / 2;
    edges[0].weight = mid;
    if (krskl(s, t)) {
      ans = mid;
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  for (int tc = 0; tc < t; tc++) {
    solve(tc + 1);
  }
}
