#include "bits/stdc++.h"
using namespace std;
#define long int64_t

template<class T>
inline istream& operator >>( istream& s, vector<T>& v ) {
	for( size_t i = 0; i < v.size(); ++i ) { s >> v[i]; }
	return s;
}

template<class T>
inline ostream& operator <<( ostream& s, vector<T>& v ) {
	for( size_t i = 0; i < v.size(); ++i ) {
		if( i ) { s << ' '; }
		s << v[i];
	}
	return s;
}

int main() {
	ios_base::sync_with_stdio( false );

	int n;
	cin >> n;

	vector<int> a( n );
	for( int i = 0; i < n; ++i ) { a[i] = i+1; }

	do {
		cout << a << '\n';
	} while( next_permutation( a.begin(), a.end() ) );

	return 0;
}

