#include <bits/stdc++.h>
using namespace std;
class UnionFind {
 public:
  int *nodes;
  int *ranks;
  UnionFind(int n) {
    nodes = new int[n];
    ranks = new int[n];
    for (int i = 0; i < n; i++) {
      nodes[i] = i;
    }
  }
  void merge(int x, int y) {
    int rootx = nodes[x];
    int rooty = nodes[y];
    if (ranks[rootx] > ranks[rooty]) {
      nodes[rooty] = rootx;
    } else if (ranks[rootx] < ranks[rooty]) {
      nodes[rootx] = rooty;
    } else if (x != y) {
      nodes[rooty] = rootx;
      ranks[rootx] += 1;
    }
  }
  int find(int x) {
    if (nodes[x] == x) {
      return x;
    }
    nodes[x] = find(nodes[x]);
    return nodes[x];
  }
  ~UnionFind() {
    delete[] ranks;
    delete[] nodes;
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  int start, end, weight;
  cin >> start >> end >> weight;
  vector<tuple<int, int, int> > edges;
  edges.push_back({1000000000, start, end});
  for (int i = 0; i < m - 1; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    edges.push_back({c, a, b});
  }
  sort(edges.begin(), edges.end());
  UnionFind uf(n + 1);
  int r = 0;
  for (auto [w, a, b] : edges) {
    if (uf.find(a) != uf.find(b)) {
      if (uf.find(start) != uf.find(end)) {
        r = w;
      } else {
        break;
      }
      uf.merge(a, b);
    }
  }
  cout << r << endl;
}
