import java.util.Scanner;
public class Main {
static int lable[]=new int[15];
static int a[]=new int[15];
static Scanner sc=new Scanner(System.in);
static int depth =sc.nextInt();
public static void print(int a[]){
for (int i = 1; i <= depth; i++) {
System.out.printf("%5d",a[i]);
}
}
public static void dfs(int currentdepth){
if(currentdepth>depth){
print(a);
System.out.println();
return;
}
for (int i = 1; i <=depth; i++) {
if(lable[i]==0){
lable[i]=1;
a[currentdepth]=i;
dfs(currentdepth+1);
lable[i]=0;
}
}
return;
}
public static void main(String[] args) {
dfs(1);
}
}