https://www.acmicpc.net/problem/1389
using System;
using System.Collections;
class Program
{
static int[,] arr;
static bool[] check;
static int n;
static int bfs(int a){
check=new bool[n+1];
Queue q=new Queue();
q.Enqueue(new int[]{a,0});
check[a]=true;
int sum=0;
while(q.Count!=0){
int[] v=(int[])q.Dequeue();
sum+=v[1];
for(int i=1;i<=n;i++){
if(arr[v[0],i]==1 && check[i]==false){
check[i]=true;
q.Enqueue(new int[]{i,v[1]+1});
}
}
}
return sum;
}
static void Main() {
string[] s=Console.ReadLine().Split(' ');
n=int.Parse(s[0]);
int m=int.Parse(s[1]);
arr=new int[n+1,n+1];
while(m-->0){
string[] s1=Console.ReadLine().Split(' ');
int a=int.Parse(s1[0]);
int b=int.Parse(s1[1]);
arr[a,b]=arr[b,a]=1;
}
int count=1000;
int ans=0;
for(int i=1;i<=n;i++){
int sum=bfs(i);
if(count>sum){
count=sum;
ans=i;
}
}
Console.Write(ans);
}
}