from itertools import permutations
def words(letters):
for n in range(1, len(letters)+1):
yield from map(’’.join, permutations(letters, n))
#leng = int(input().strip())
#arr = int(input().strip())
leng = int(input())
arr = int(input())
#leng=2
#arr=4
#leng, arr = map(int, input().split())
s=""
i=0
while i<arr:
s1=input(’’)
s=s+s1
i=i+1
l=[]
for word in words(s):
if len(word)==leng:
l.append(word)
count=0
a=sorted(l)
for elements in a:
print(elements)
count=count+1
print(count)