#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <utility>

using namespace std;

typedef pair<int, int> pii;

struct UF {
    vector<int> data;

    UF(int n) {
        data.resize(n, -1);
    }

    int root(int i) {
        return data[i] < 0 ? i : data[i] = root(data[i]);
    }

    int size(int i) {
        return -data[root(i)];
    }

    void unite(int x, int y) {
        x = root(x), y = root(y);

        if (x == y) return ;

        if (size(x) < size(y)) swap(x, y);

        data[x] += data[y];
        data[y] = x;
    }

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

int N, M;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    while (cin >> N >> M, N) {
        UF uf(N);

        vector<pair<int, pii>> edges;

        for (int i = 0; i < M; ++i) {
            int s, t, c; cin >> s >> t >> c;

            --s, --t;

            edges.push_back(make_pair(c, pii(s, t)));
        }

        sort(begin(edges), end(edges));

        vector<int> a;

        for (pair<int, pii> e : edges) {
            int cost = e.first;
            pii info = e.second;
            if (!uf.same(info.first, info.second)) {
                uf.unite(info.first, info.second);
                a.push_back(cost);
            }
        }

        sort(begin(a), end(a));

        cout << a[a.size() / 2] << endl;
    }
}