#include <bits/stdc++.h>
using namespace std;
#define N 20005
#define M 100005
struct Edge
{
int u,v,cost;
bool operator < (const Edge s) const
{
return s.cost < cost;
}
} edge,h[M];
vector<int> q[N];
int color[N];
bool dfs(int n,int fa,int col)
{
color[n] = col;
for(int i = 0;i < q[n].size();i++)
{
if(q[n][i] == fa) continue;
if(color[q[n][i]] == color[n]) return 0;
if(dfs(q[n][i],n,-col) == 0) return 0;
}
return 1;
}
int z = -114514;
bool check(int y)
{
if(z != -114514)
{
if(y - z > 0)
{
for(int i = z + 1;i <= y;i++)
{
q[h[i].u].push_back(h[i].v);
q[h[i].v].push_back(h[i].u);
}
}
else
{
for(int i = z - y;i >= 1;i--)
{
q[h[i + y].u].pop_back();
q[h[i + y].v].pop_back();
}
}
}
memset(color,0,sizeof(color));
z = y;
return dfs(1,-1,114514);
}
int main()
{
int n,m;
cin >> n >> m;
int u,v,w;
for(int i = 1;i <= m;i++)
{
cin >> u >> v >> w;
edge.u = u;
edge.v = w;
edge.cost = w;
h[i] = edge;
}
sort(h + 1,h + m + 1);
reverse(h + 1,h + m + 1);
int l = 1,r = m;
while(l <= r)
{
int mid = (l + r) >> 1;
if(check(mid)) l = mid + 1;
else r = mid - 1;
}
cout << h[l].cost;
return 0;
}