#permutations code from class work

infile = open('permutations.in', 'r')
outfile = open('permutations.out', 'w')

n = int(infile.readline().strip())
def gen_perm(a, p):
	if p < n:
		for i in range(1, n+1):
			if i not in a:
				a[p] = i
				gen_perm(a, p+1) 
				a[p] = 0
	else:
		outfile.write(str.join(' ', (str(i) for i in a))+'\n')

gen_perm([0 for i in range (n)], 0)

infile.close()
outfile.close()