#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define EPS 1e-10
#define MOD 1000000007
using namespace std;
typedef pair<int,int> P;

struct UF{
	int par[1000];
	int rank[1000];

	void init(int n){
		rep(i,n){
			par[i] = i;
			rank[i] = 0;
		}
	}

	int find(int x){
		if(par[x] == x) return x;
		else return par[x] = find(par[x]);
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		
		if(rank[x] < rank[y]) par[x] = y;
		else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int n, m;
vector<P> v[1000];
UF uf;

void solve(){
	rep(i,1000) v[i].clear();
	rep(i,m){
		int s, t, c;
		cin >> s >> t >> c;
		s--; t--;
		v[s].push_back(P(t,c));
	}
	int s = 0, e = 10000, mid;
	while(true){
		if(e-s == 1) break;
		mid = (s+e)/2;
		uf.init(n);
		rep(i,n){
			rep(j,v[i].size()){
				P p = v[i][j];
				if(p.second <= mid) uf.unite(i,p.first);
			}
		}
		int cnt = 0;
		rep(i,n) if(uf.par[i] == i) cnt++;
		if(cnt <= n/2) e = mid;
		else s = mid;
	}
	cout << e << endl;
}

int main(){
	while(cin >> n >> m){
		if(n == 0 && m == 0) break;
		solve();
	}
}