//dfs深度优先遍历1.回溯(依靠算法递归完成) 2,剪枝
import java.util.*;
public class Main{
static int N = 10;
static int n;
static int[] path = new int[N];//用来组装队列
static int[] stat = new int[N];//判断数字是否被用过
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
dfs(0);
}
private static void dfs(int u){
if(u >= n){
for(int i = 0;i < n;i++){
System.out.print(path[i] + " ");
}
System.out.println();
}
for(int i = 1; i <= n;i++){
if(stat[i] == 0){
path[u] = i;
stat[i] = 1;
dfs(u + 1);
stat[i] = 0;
}
}
}
}