#include<bits/stdc++.h>
using namespace std ;
int a[10] , n ;
bool b[10] ;
void print()
{
for(int i = 1 ; i <= n ; i ++)
cout << a[i] << " " ;
cout << endl ;
}
void go(int dep)
{
for(int i = 1 ; i <= n ; i ++)
if(b[i] == 0)
{
a[dep] = i ;
b[i] = 1 ;
if(dep == n)
print() ;
else
go(dep + 1) ;
b[i] = 0 ;
}
}
int main()
{
cin >> n ;
go(1);
return 0 ;
}