import java.util.*

fun main(args:Array<String>?): Unit {
    while(true){
        val (n, m) = readLine()!!.trim().split(' ').map(String::toInt)
        if (n == 0 && m == 0) return
        val union = UnionFind(n)
        val edges = Array(m){
            val (s, t, c) = readLine()!!.trim().split(' ').map(String::toInt)
            Triple(s - 1, t - 1, c)
        }.sortedBy(Triple<Int, Int, Int>::third)
        val used = Stack<Int>()
        for ((s, t, c) in edges){
            if (!union.isSame(s, t)) {
                used.push(c)
                union.merge(s, t)
            }
        }
        used.sort()
        println(
                used[used.size / 2]
        )
    }
}
class UnionFind(val size: Int){
    private val array = IntArray(size){-1}
    private fun find(a: Int): Int {
        val root = root(a)
        setRoot(a, root)
        return root
    }
    private tailrec fun root(a: Int): Int {
        return if (array[a] < 0) a else root(array[a])
    }
    private fun setRoot(a: Int, root: Int) {
        if (a != root) {
            setRoot(array[a], root)
            array[a] = root
        }
    }
    fun isSame(u: Int, v: Int): Boolean {
        return find(u) == find(v)
    }
    fun merge(u: Int, v: Int) {
        val ur = find(u)
        val vr = find(v)
        if (ur != vr){
            if (array[ur] < array[vr]){
                array[ur] += array[vr]
                array[vr] = ur
            }else {
                array[vr] += array[ur]
                array[ur] = vr
            }
        }
    }
}
