using namespace std;
#define MAXN 10 + 1;
int n;int a[MAXN], p[MAXN];
void print(){ int i; for( i = 1; i < n; ++i ) cout << a[i] << ' '; cout << a[i] << endl;}
void DFS( int dep ){ if( dep > n ) print(); else { for( int i = 1; i <= n; ++i ) { if( p[i] ) { a[dep] = i; p[i] = 0; DFS( dep + 1 ); p[i] = 1; } } }}
int main(){ cin >> n; memset( p, 1, sizeof(p) );
DFS(1);
return 0;}
#include
#define MAXN 10 + 1
int n;int a[MAXN], p[MAXN];
void print(){ int i; for( i = 1; i <= n; ++i ) printf( "%d ", a[i] ); putchar('\n');}
void DFS( int dep ){ if( dep > n ) { print(); return; } else { for( int i = 1; i <= n; ++i ) { if( p[i] ) { a[dep] = i; p[i] = 0; DFS( dep + 1 ); p[i] = 1; } } }}
int main(){ scanf( "%d", &n ); memset( p, 1, sizeof(p) );
DFS(1);
return 0;}