import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

struct Edge {
    int s, t, c;
}

class UnionFind {
    int[] parent;
    this(int size) {
        parent = new int[size];
        parent[] = -1;
    }
    int root(int x) {
        if (parent[x] < 0) return x;
        return parent[x] = root(parent[x]);
    }
    int query(int x, int y) {
        return root(x) == root(y);
    }
    void merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return;
        parent[y] = x;
    }
}
 
void main() {
    int N, M;
    Edge[] es;

    bool input() {
        scanf("%d %d\n", &N, &M);
        if (N == 0 && M == 0) return false;
        es = [];
        foreach (i; 0 .. M) {
            int s, t, c;
            scanf("%d %d %d", &s, &t, &c);
            s--; t--;
            es ~= Edge(s, t, c);
        }
        return true;
    }

    void solve() {
        auto uf = new UnionFind(N);
        int[] cs;
        es.sort!"a.c < b.c";
        foreach (e; es) {
            if (uf.query(e.s, e.t)) continue;
            uf.merge(e.s, e.t);
            cs ~= e.c;
        }
        writeln(cs[$ / 2]);
    }

    while (input) solve;
}