//KZNS
#include <cstdio>
#include <algorithm>
using namespace std;
#define Nmax 20003
#define Mmax 100003
class poi {
public:
int a, b, c;
};
bool operator < (const poi &a, const poi &b) {
return a.c > b.c;
}
int N, M;
poi ls[Mmax];
int fa[Nmax];
bool fd[Nmax] = {0};
void rin() {
scanf("%d %d", &N, &M);
for (int i = 0; i < M; i++)
scanf("%d %d %d", &ls[i].a, &ls[i].b, &ls[i].c);
for (int i = 1; i <= N; i++)
fa[i] = i;
}
int FA(int x) {
if (fa[x] == x)
return x;
int f = fa[x];
fa[x] = FA(fa[x]);
fd[x] ^= fd[f];
return fa[x];
}
void work() {
sort(ls, ls+M);
int ans = 0;
int a, b, c;
for (int i = 0; i < M; i++) {
a = ls[i].a;
b = ls[i].b;
c = ls[i].c;
if (FA(a) == FA(b)) {
if (fd[a] == fd[b]) {
ans = c;
break;
}
}
else {
fd[fa[a]] = !(fd[a] ^ fd[b]);
fa[fa[a]] = fa[b];
}
}
printf("%d\n", ans);
}
int main() {
freopen("prison1.in", "r", stdin);
freopen("prison1.out", "w", stdout);
rin();
work();
return 0;
}
//UBWH