https://www.acmicpc.net/problem/10813
import java.io.*;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine()," ");
// N개 바구니
int N = Integer.parseInt(st.nextToken());
int[] arr = new int[N];
// 바구니 바꿀 번수
int M = Integer.parseInt(st.nextToken());
// 초기 공번호
for(int i =0 ; i<N; i++){
arr[i] = i+1;
}
// 바꿀 공번호
while(M-- > 0){
st = new StringTokenizer(br.readLine()," ");
int i = Integer.parseInt(st.nextToken());
int j = Integer.parseInt(st.nextToken());
int temp = arr[i-1];
arr[i-1] = arr[j-1];
arr[j-1] = temp;
}
for(int i=0; i<N; i++){
System.out.print(arr[i]+ " ");
}
}
}