https://www.acmicpc.net/problem/10811
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
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());
int basket = Integer.parseInt(st.nextToken());
int count = Integer.parseInt(st.nextToken());
int[] basketArray = new int[basket];
for(int i = 0; i < basket; i++){
basketArray[i] = i+1;
}
for(int i = 0; i < count; i++){
st = new StringTokenizer(br.readLine());
int from = Integer.parseInt(st.nextToken()) -1;
int to = Integer.parseInt(st.nextToken()) -1;
while(from < to){
int temp = basketArray[from];
basketArray[from] = basketArray[to];
basketArray[to] = temp;
from++;
to--;
}
}
for(int i = 0; i < basket; i++){
System.out.print(basketArray[i]+ " ");
}
}
}