https://www.acmicpc.net/problem/1389
import java.util.*;
public class Main {
static int arr[][];
static boolean check[];
static int n;
static int bfs(int a){
check=new boolean[n+1];
Queue<int[]> q=new LinkedList<>();
q.add(new int[]{a,0});
check[a]=true;
int sum=0;
while(!q.isEmpty()){
int v[]=q.poll();
sum+=v[1];
for(int i=1;i<=n;i++){
if(arr[v[0]][i]==1 && check[i]==false){
check[i]=true;
q.add(new int[]{i,v[1]+1});
}
}
}
return sum;
}
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
n=s.nextInt();
int m=s.nextInt();
arr=new int[n+1][n+1];
while(m-->0){
int a=s.nextInt();
int b=s.nextInt();
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;
}
}
System.out.print(ans);
}
}