#include <bits/stdc++.h>
using namespace std;
typedef struct set_t {
  vector<int> rank;
  vector<int> parent;
} set_t;
set_t new_set(int n) {
  set_t s;
  s.rank = vector<int>(n, 0);
  s.parent = vector<int>(n);
  for (int i = 0; i < n; i++) s.parent[i] = i;
  return s;
}
int find_set(set_t& s, int a) {
  if (s.parent[a] == a) return a;
  s.parent[a] = find_set(s, s.parent[a]);
  return s.parent[a];
}
void union_set(set_t& s, int a, int b) {
  a = find_set(s, a);
  b = find_set(s, b);
  if (a == b) return;
  if (s.rank[a] == s.rank[b]) {
    s.parent[b] = a;
    s.rank[a]++;
  } else if (s.rank[a] > s.rank[b]) {
    s.parent[b] = a;
  } else {
    s.parent[a] = b;
  }
}
bool comp(vector<int>& a, vector<int>& b) { return a[2] < b[2]; }
int main() {
  int n, m;
  cin >> n >> m;
  set_t s = new_set(n);
  vector<vector<int> > graph(m, vector<int>(3)), cut_edges;
  int u, v, x, y, w, w1;
  cin >> u >> v >> w1;
  graph[0][0] = --u;
  graph[0][1] = --v;
  graph[0][2] = w1;
  for (int i = 1; i < m; i++) {
    cin >> x >> y >> w;
    graph[i][0] = --x;
    graph[i][1] = --y;
    graph[i][2] = w;
  }
  sort(graph.begin(), graph.end(), comp);
  for (int i = 0; i < m; i++) {
    if ((find_set(s, u) == find_set(s, graph[i][0]) &&
         find_set(s, v) == find_set(s, graph[i][1])) or
        (find_set(s, u) == find_set(s, graph[i][1]) &&
         find_set(s, v) == find_set(s, graph[i][0]))) {
      cut_edges.push_back(graph[i]);
    } else {
      union_set(s, graph[i][0], graph[i][1]);
    }
  }
  if (cut_edges.size() == 1) {
    cout << 1000000000;
  } else {
    if (w1 == cut_edges[0][2]) {
      int i;
      for (i = 0; i < cut_edges.size(); i++)
        if (cut_edges[i][2] != w1) break;
      if (i == cut_edges.size()) {
        cout << w1;
      } else {
        cout << cut_edges[i][2];
      }
    } else {
      cout << cut_edges[0][2];
    }
  }
}
