#include <bits/stdc++.h>
using namespace std;
priority_queue<long long, vector<long long>, greater<long long>> pq1, pq2;
long long power(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    res *= a;
    b--;
  }
  return res;
}
long long parent[200005], sz[200005], visit[200005] = {0}, cnt[200005] = {0};
vector<pair<long long, long long>> vt[200005];
vector<long long> v[200005];
struct Test {
  long long a, b, c;
};
bool comp(const Test &p1, const Test &p2) { return p1.a < p2.a; }
long long find_parent(long long a) {
  if (a == parent[a])
    return a;
  else
    return parent[a] = find_parent(parent[a]);
}
long long dfs(long long a) {
  visit[a] = 1;
  cnt[a]++;
  for (int i = 0; i < v[a].size(); ++i) {
    long long b = v[a][i];
    if (visit[b] == 0) {
      dfs(b);
    }
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m, x, y, st1, st2, z;
  vector<Test> w;
  cin >> n >> m;
  long long cnt1 = 0;
  for (int i = 0; i < m; ++i) {
    cin >> x >> y >> z;
    vt[x].push_back({y, z});
    vt[y].push_back({x, z});
    if (cnt1 == 0) {
      w.push_back({0, x, y});
      st1 = x;
      st2 = y;
    } else
      w.push_back({z, x, y});
    cnt1++;
  }
  for (int i = 1; i < n + 1; ++i) {
    sz[i] = 0;
    parent[i] = i;
  }
  sort(w.begin(), w.end(), comp);
  for (int i = 0; i < w.size(); ++i) {
    long long p1 = w[i].b;
    long long p2 = w[i].c;
    long long par1 = find_parent(p1);
    long long par2 = find_parent(p2);
    if (par1 != par2) {
      v[p1].push_back(p2);
      v[p2].push_back(p1);
      if (sz[par1] <= sz[par2]) {
        sz[par2] += sz[par1];
        parent[par1] = par2;
      } else {
        sz[par1] += sz[par2];
        parent[par2] = par1;
      }
    }
  }
  if (v[st1].size() == 1) {
    if (vt[st1].size() == 1)
      cout << "1000000000" << endl;
    else {
      long long mn = 1000000000;
      for (int j = 0; j < vt[st1].size(); ++j) {
        if (v[st1][j] == st2) continue;
        mn = min(mn, vt[st1][j].second);
      }
      cout << mn << endl;
    }
  } else {
    visit[st1] = 1;
    dfs(st2);
    long long mn = 1000000000;
    for (int i = 1; i < n + 1; ++i) {
      if (cnt[i] > 0) {
        for (int j = 0; j < vt[i].size(); ++j) {
          if (i == st2 && vt[i][j].first == st1) continue;
          if (cnt[vt[i][j].first] == 0) mn = min(mn, vt[i][j].second);
        }
      }
    }
    cout << mn << endl;
  }
  return 0;
}
