#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
long long int powmod(long long int a, long long int b) {
  long long int res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int nxt() {
  int x;
  scanf("%d", &x);
  return x;
}
class UnionFind {
 private:
  vector<int> p, rank, setSize;
  int numSets;

 public:
  UnionFind(int N) {
    setSize.assign(N, 1);
    numSets = N;
    rank.assign(N, 0);
    p.assign(N, 0);
    for (int i = 0; i < N; i++) p[i] = i;
  }
  int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
  bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
  void unionSet(int i, int j) {
    if (!isSameSet(i, j)) {
      numSets--;
      int x = findSet(i), y = findSet(j);
      if (rank[x] > rank[y]) {
        p[y] = x;
        setSize[x] += setSize[y];
      } else {
        p[x] = y;
        setSize[y] += setSize[x];
        if (rank[x] == rank[y]) rank[y]++;
      }
    }
  }
  int numDisjointSets() { return numSets; }
  int sizeOfSet(int i) { return setSize[findSet(i)]; }
};
int main() {
  vector<pair<int, pair<int, int>>> edges;
  int n = nxt(), ma = nxt();
  map<int, int> m;
  for (int i = 0; i < ma; i++) {
    int a = nxt(), b = nxt(), c = nxt();
    if (m.count(a) == 0) m[a] = m.size();
    if (m.count(b) == 0) m[b] = m.size();
    edges.push_back({c, {m[a], m[b]}});
  }
  int low = 0, high = 1e9;
  int l = edges[0].second.first, r = edges[0].second.second;
  while (low < high) {
    int mid = low + (high - low + 1) / 2;
    edges[0].first = mid;
    vector<pair<int, pair<int, int>>> tmp = edges;
    sort((tmp).begin(), (tmp).end());
    UnionFind uf(n);
    bool poss = false;
    for (int i = 0; i < ma; i++) {
      if (!uf.isSameSet(tmp[i].second.first, tmp[i].second.second)) {
        uf.unionSet(tmp[i].second.first, tmp[i].second.second);
        if (tmp[i].second.first == l && tmp[i].second.second == r) {
          poss = true;
        }
      }
    }
    if (poss) {
      low = mid;
    } else
      high = mid - 1;
  }
  printf("%d\n", low);
  return 0;
}
