mag,tov=map(int,input().split())
a=list(map(int,input().split()))
b=[]
buf=0
for i in range(mag):
    b=a[:tov]
    del a[:tov]
    if list(set(b))!=b:
        a.append(b)
mag=len(a)
rents=[]
zalyshs=[]
for i in range(mag):

    rents.append([])
    zalyshs.append([])
    for t in range(1,tov+1):
        if not t in a[i]:
            rents[-1].append(t)
        if a[i].count(t)>1:
            for y in range(a[i].count(t)-1):
                zalyshs[-1].append(t)
print(rents)
print(zalyshs)