https://www.acmicpc.net/problem/1389
import java.util.*;
var arr=Array(0, {Array(0, {0})})
var check=Array(0, {false})
var n: Int=0
fun bfs(a:Int):Int{
check=Array(n+1, {false})
var q=LinkedList<Int>()
var w=LinkedList<Int>()
q.add(a)
w.add(0)
check[a]=true
var sum=0
while(!q.isEmpty()){
val v0=q.poll()
val v1=w.poll()
sum+=v1
for(i in 1..n){
if(arr[v0][i]==1 && check[i]==false){
check[i]=true
q.add(i)
w.add(v1+1)
}
}
}
return sum
}
fun main(args: Array<String>) {
val s=Scanner(System.`in`)
n=s.nextInt()
var m=s.nextInt()
arr=Array(n+1, {Array(n+1, {0})})
while(m-->0){
var u=s.nextInt()
var v=s.nextInt()
arr[u][v]=1
arr[v][u]=1
}
var count=1000
var ans=0
for(i in 1..n){
var sum=bfs(i)
if(count>sum){
count=sum
ans=i
}
}
print(ans)
}