One day Ms Swan bought an orange in a shop. The orange consisted of n·k segments, numbered with integers from 1 to n·k. 

There were k children waiting for Ms Swan at home. The children have recently learned about the orange and they decided to divide it between them. For that each child took a piece of paper and wrote the number of the segment that he would like to get: the i-th (1 ≤ i ≤ k) child wrote the number a_{i} (1 ≤ a_{i} ≤ n·k). All numbers a_{i} accidentally turned out to be different.

Now the children wonder, how to divide the orange so as to meet these conditions:  each child gets exactly n orange segments;  the i-th child gets the segment with number a_{i} for sure;  no segment goes to two children simultaneously. 

Help the children, divide the orange and fulfill the requirements, described above.


-----Input-----

The first line contains two integers n, k (1 ≤ n, k ≤ 30). The second line contains k space-separated integers a_1, a_2, ..., a_{k} (1 ≤ a_{i} ≤ n·k), where a_{i} is the number of the orange segment that the i-th child would like to get.

It is guaranteed that all numbers a_{i} are distinct.


-----Output-----

Print exactly n·k distinct integers. The first n integers represent the indexes of the segments the first child will get, the second n integers represent the indexes of the segments the second child will get, and so on. Separate the printed numbers with whitespaces.

You can print a child's segment indexes in any order. It is guaranteed that the answer always exists. If there are multiple correct answers, print any of them.


-----Examples-----
Input
2 2
4 1

Output
2 4 
1 3 

Input
3 1
2

Output
3 2 1

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
(n, k) = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ')]
b = [i for i in range(1, n * k + 1) if i not in a]
for i in range(k):
	print(*[a[i]] + b[i * (n - 1):(i + 1) * (n - 1)])


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
lst = [i for i in range(1, n * k + 1) if i not in arr]
for num in arr:
	ans = [num]
	cases = n - 1
	while cases:
		ans.append(lst.pop())
		cases -= 1
	print(*ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = set(a)
ans = []
for i in a:
	ans.append([i])
x = 0
y = 0
for j in range(1, n * k + 1):
	if j not in b:
		if x <= n - 2:
			x += 1
		else:
			y += 1
			x = 1
		ans[y].append(j)
for res in ans:
	print(*res)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
l = []
c = 0
r = 0
c1 = 0
for i in range(1, n * k + 1):
	if i not in a:
		l.append(i)
		c += 1
	if c > 0 and c % (n - 1) == 0 and (c > r):
		r1 = c1 * (n - 1)
		r2 = c
		print(a[c1], end=' ')
		print(*l[r1:r2], sep=' ')
		r = c
		c1 += 1
	if n == 1:
		print(a[i - 1])


(n, k) = map(int, input().split(' '))
wished_slices = input().split(' ')
wished_slices = [int(el) for el in wished_slices]
start_slice = 1
total_slices = n * k
for child in range(0, k):
	print(wished_slices[child], end=' ')
	slices_given = 1
	for slice in range(1, total_slices + 1):
		if slice not in wished_slices:
			print(slice, end=' ')
			wished_slices.append(slice)
			slices_given = slices_given + 1
		if slices_given >= n:
			break
	print()


def read_int():
	return int(input())

def read_ints():
	return list(map(int, input().split()))

def print_nums(nums):
	print(' '.join(map(str, nums)))
(n, k) = read_ints()
seg = read_ints()
vis = set(seg)
step = 1
for i in range(k):
	ans = [seg[i]]
	while len(ans) < n:
		if step not in vis:
			ans.append(step)
		step += 1
	print_nums(ans)


(n, k) = [int(i) for i in input().split()]
nk = n * k
ls_ = [int(i) for i in input().split()]
marks_ = [False] * (nk + 1)
c = 1
for i in ls_:
	marks_[i] = True
for i in range(k):
	print(ls_[i], end=' ')
	for j in range(1, n):
		while marks_[c] == True:
			c += 1
		if j != n - 1:
			print(c, end=' ')
		else:
			print(c, end='')
		marks_[c] = True
	if i != k - 1:
		print()


def main():
	(n, k) = map(int, input().split())
	l = list(range(1, n * k + 1))
	aa = list(map(int, input().split()))
	for a in aa:
		l[a - 1] = False
	l = list(filter(None, l))
	n -= 1
	for (i, a) in enumerate(aa):
		print(a, *l[i * n:(i + 1) * n])

def __starting_point():
	main()
__starting_point()


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
o = []
for i in range(n * m):
	o.append(0)
for i in range(m):
	o[a[i] - 1] = i + 1
for i in range(m):
	for j in range(n - 1):
		for k in range(n * m):
			if o[k] == 0:
				print(k + 1, end=' ')
				o[k] = i + 1
				break
	print(a[i], end='\n')


inp = list(map(int, input().split()))
(n, k) = inp
arr = []
for i in range(k + 1):
	arr.append([])
from collections import Counter
a = list(map(int, input().split()))
for i in range(len(a)):
	arr[i + 1].append(a[i])
c = Counter(a)
j = 1
for i in range(1, n * k + 1):
	if c[i] != 0:
		continue
	if len(arr[j]) == n:
		j += 1
		if j == len(arr):
			break
	arr[j].append(i)
	c[i] += 1
for item in arr:
	for k in item:
		print(k, end=' ')
	print(' ')


c = 1

def main():
	(n, k) = map(int, input().split())
	l = list(range(1, n * k + 1))
	aa = list(map(int, input().split()))
	for a in aa:
		l[a - 1] = 0
	(res, it) = ([], iter(filter(None, l)))
	n -= 1
	for a in aa:
		res.append(a)
		for _ in range(n):
			res.append(next(it))
		print(' '.join(map(str, res)))
		res.clear()
main()


(n, k) = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
z = [i + 1 for i in range(n * k)]
y = [[] for i in range(k)]
for i in range(k):
	y[i].append(x[i])
	z.remove(x[i])
while len(z) > 0:
	for i in range(k):
		y[i].append(z[0])
		z.remove(z[0])
for i in y:
	for j in i:
		print(j, end=' ')
	print('')


(k, n) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = a + [n * k + 1]
b.sort()
j = 1
t = []
for i in b:
	t += list(range(j, i))
	j = i + 1
x = 0
k -= 1
for i in range(n):
	print(str(a[i]) + ' ' + ' '.join((str(j) for j in t[x:x + k])))
	x += k


(n, k) = map(int, input().split())
l = n * k + 1
Count = [0] * l
Count[0] = 1
A = [int(x) for x in input().split()]
B = []
for i in A:
	Count[i] = 1
	B.append([i])
index = 1
for i in range(k):
	cnt = 0
	while cnt != n - 1:
		while index < l and Count[index] == 1:
			index += 1
		while index < l and Count[index] == 0 and (cnt != n - 1):
			cnt += 1
			B[i].append(index)
			Count[index] = 1
			index += 1
for i in B:
	for j in i:
		print(j, end=' ')
	print()


[n, k] = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
arr = list(range(1, n * k + 1))
for i in a:
	arr[i - 1] = 0
j = 0
for i in a:
	print(i, end=' ')
	count = 1
	while count < n:
		if arr[j] != 0:
			print(arr[j], end=' ')
			count = count + 1
		j = j + 1
	print('')


a = list(map(int, input().split(' ')))
s = []
s1 = []
for i in range(1, a[0] * a[1] + 1):
	s.append(i)
s1 = list(map(int, input().split(' ')))
g = list(set(s) - set(s1))
x = 0
for i in range(a[1]):
	print(s1[i], end=' ')
	for j in range(a[0] - 1):
		print(g[x], end=' ')
		x += 1
	print()


(n, k) = map(int, input().split())
d = {}
l = []
for s in input().split():
	s = int(s)
	d[s] = True
	l.append(s)
for s in l:
	print(s, end='')
	c = 1
	for i in range(1, n * k + 1):
		if d.get(i) is None:
			print('', i, end='')
			d[i] = True
			c += 1
			if c == n:
				break
	print()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
slices = [i for i in range(1, n * k + 1)]
children = [[] for i in range(k)]
for i in range(k):
	seg = a[i]
	children[i].append(seg)
	slices.remove(seg)
for (i, seg) in enumerate(slices):
	children[i % k].append(seg)
for child in children:
	print(' '.join([str(s) for s in child]))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
i = 1
for j in range(k):
	m = [l[j]]
	while len(m) != n:
		if i in l:
			i += 1
		else:
			m.append(i)
			i += 1
	print(' '.join((str(m[z]) for z in range(n))))


(n, k) = map(int, input().split())
s = [int(i) for i in input().split()]
a = [x for x in range(1, n * k + 1) if x not in s]
for i in range(k):
	print(s[i], *a[i * (n - 1):(i + 1) * (n - 1)])


(n, k) = [int(x) for x in input().split()]
ai = [int(x) for x in input().split()]
cnt = 0
c = 0
line = 0
for i in range(1, n * k + 1):
	if c == 0 and line != k:
		print(ai[cnt], end=' ')
		c += 1
		line += 1
	if i not in ai and c != n:
		print(i, end=' ')
		c += 1
	if c == n:
		c = 0
		cnt += 1
		print()


arr1 = []
arr2 = []
x = str(input(''))
arr1 = x.split()
for z in range(0, 2):
	z1 = arr1[z]
	arr2.append(int(z1))
arr3 = []
arr4 = []
x = str(input(''))
arr3 = x.split()
for z in range(0, arr2[1]):
	z1 = arr3[z]
	arr4.append(int(z1))
comp = []
for i in range(1, arr2[0] * arr2[1] + 1):
	comp.append(i)
arr5 = []
for j in range(0, arr2[0] * arr2[1]):
	if j < arr2[1]:
		arr5.append(arr4[j])
		comp.remove(arr4[j])
	else:
		arr5.append(comp[j - arr2[1]])
for m in range(0, arr2[1]):
	for s in range(0, arr2[0]):
		print(arr5[m:arr2[0] * arr2[1]:arr2[1]][s], end=' ')
	print('\n')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = set([x for x in range(1, n * k + 1)])
for i in a:
	s.remove(i)
for i in range(k):
	c = []
	c.append(str(a[i]))
	for _ in range(1, n):
		c.append(str(s.pop()))
	print(' '.join(c))


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
oranges = list(range(1, n * k + 1))
child = {i: [] for i in range(1, k + 1)}
for i in range(k):
	child[i + 1].append(arr[i])
remain = list(set(oranges) - set(arr))
ptr = 0
for i in range(k):
	child[i + 1].extend(remain[ptr:ptr + n - 1])
	ptr += n - 1
	print(*child[i + 1])


(number_per_child, number_of_children) = input().strip().split()
number_per_child = int(number_per_child)
number_of_children = int(number_of_children)
number_of_segs = number_of_children * number_per_child
priority = input().strip().split()
prefarence = {}
for i in range(0, len(priority)):
	priority[i] = int(priority[i])
	prefarence[priority[i]] = i
distribution = {}
for i in range(0, number_of_children):
	distribution[i] = []
temp = 1
for x in distribution:
	count = 0
	while count < number_per_child - 1:
		if not temp in prefarence:
			distribution[x].append(temp)
			temp = temp + 1
			count = count + 1
		else:
			temp = temp + 1
for x in prefarence:
	distribution[prefarence[x]].append(x)
ans = ''
for x in distribution:
	for y in distribution[x]:
		ans = ans + str(y) + ' '
	if x != number_of_children - 1:
		ans = ans + '\n'
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
j = 1
l = 1
for i in range(k):
	print(a[i], end=' ')
	while l != n:
		if j not in a:
			print(j, end=' ')
			l += 1
		j += 1
	l = 1
	print('\n')


I = lambda : map(int, input().split())
(n, k) = I()
a = list(I())
b = list(range(1, n * k + 1))
for i in a:
	b.remove(i)
for i in range(k):
	print(' '.join(map(str, [a[i]] + b[i * (n - 1):i * (n - 1) + n - 1])))


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
s = [False] * (n * k + 1)
for ai in a:
	s[ai] = True
for kid in range(k):
	curN = 1
	print(a[kid], end=' ')
	for num in range(n - 1):
		while s[curN]:
			curN += 1
		s[curN] = True
		print(curN, end=' ')
	print('')


(n, k) = input().split()
n = int(n)
k = int(k)
arr = []
for i in range(1, n * k + 1):
	arr.append(i)
l = list(map(int, input().split()))
x = 0
for i in range(0, k):
	arr.remove(l[i])
for i in range(0, k):
	print(l[i], end=' ')
	for j in range(0, n - 1):
		print(arr[x], end=' ')
		x = x + 1
	print()


__author__ = 'Esfandiar'
import sys
from collections import defaultdict
input = sys.stdin.readline
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
seen = dict()
for i in a:
	seen[i] = 1
for i in range(k):
	ans = [a[i]]
	t = 1
	for j in range(1, n * k + 1):
		if seen.get(j, -1) == -1:
			ans.append(j)
			t += 1
			seen[j] = 1
			if t == n:
				break
	print(*ans)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
l1 = []
ans = n * k
for i in range(1, ans + 1):
	l1.append(i)
l2 = []
N = n - 1
for i in range(len(l1)):
	if l1[i] in l:
		continue
	else:
		l2.append(l1[i])

def divide_chunks(l, n):
	for i in range(0, len(l), n):
		yield l[i:i + n]
if n == 1:
	for i in range(len(l)):
		print(l[i])
else:
	l3 = list(divide_chunks(l2, N))
	for i in range(len(l3)):
		l3[i].append(l[i])
		print(*l3[i])


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
if n == 1:
	for i in arr:
		print(i)
else:
	c = 1
	for i in range(k):
		print(arr[i], end=' ')
		con = 1
		x = 0
		while con:
			if c not in arr:
				print(c, end=' ')
				x = x + 1
			c = c + 1
			if x == n - 1:
				print()
				break


(n, k) = map(int, input().split())
l1 = list(range(1, n * k + 1))
l2 = list(map(int, input().split()))
d1 = {}
for item in l2:
	d1[item] = 1
x = 0
for i in range(1, k + 1):
	z = 1
	print(l2[i - 1], end=' ')
	while z < n:
		if l1[x] not in l2:
			print(l1[x], end=' ')
			z += 1
		x += 1
	print('')


(n, k) = map(int, input().split())
ls = list(map(int, input().split()))
ps = [q for q in range(1, n * k + 1) if q not in ls]
ps = iter(ps)
for i in range(k):
	print(ls[i], end=' ')
	for q in range(n - 1):
		print(next(ps), end=' ')
	print()


import math
import sys
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)
(n, k) = mi()
a = li()
sa = set(a)
t = []
for i in range(1, n * k + 1):
	if i not in sa:
		t.append(i)
for i in range(k):
	print(a[i], end=' ')
	for j in range(n - 1):
		print(t.pop(), end=' ')
	print()


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
rs = [[i] for i in a]
pos = 0
for i in range(n * k):
	if i + 1 in a:
		continue
	rs[pos].append(i + 1)
	pos += 1
	if pos >= k:
		pos = 0
print('\n'.join((' '.join((str(x) for x in l)) for l in rs)))


(n, k) = list(map(int, input().split()))
p = []
a = list(map(int, input().split()))
for i in range(1, n * k + 1):
	if i not in a:
		p.append(i)
for i in range(k):
	print(a[i], *p[i * (n - 1):(i + 1) * (n - 1)])


from __future__ import division, print_function
import math
import os
import sys
from fractions import *
from sys import stdin, stdout
from io import BytesIO, IOBase
from itertools import accumulate
from collections import deque

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def inpu():
	return int(inp())
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def regularbracket(t):
	p = 0
	for i in t:
		if i == '(':
			p += 1
		else:
			p -= 1
		if p < 0:
			return False
	else:
		if p > 0:
			return False
		else:
			return True

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def reverse1(string):
	pp = ''
	for i in string[::-1]:
		pp += i
	if pp == string:
		return True
	return False

def reverse2(list1):
	l = []
	for i in list1[::-1]:
		l.append(i)
	if l == list1:
		return True
	return False

def mex(list1):
	p = max(list1) + 1
	for i in range(len(list1)):
		if list1[i] != i:
			p = i
			break
	return p

def sumofdigits(n):
	n = str(n)
	s1 = 0
	for i in n:
		s1 += int(i)
	return s1

def perfect_square(n):
	s = math.sqrt(n)
	if s == int(s):
		return True
	return False

def roman_number(x):
	if x > 15999:
		return
	value = [5000, 4000, 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
	symbol = ['F', 'MF', 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
	roman = ''
	i = 0
	while x > 0:
		div = x // value[i]
		x = x % value[i]
		while div:
			roman += symbol[i]
			div -= 1
		i += 1
	return roman

def soretd(s):
	for i in range(1, len(s)):
		if s[i - 1] > s[i]:
			return False
	return True

def countRhombi(h, w):
	ct = 0
	for i in range(2, h + 1, 2):
		for j in range(2, w + 1, 2):
			ct += (h - i + 1) * (w - j + 1)
	return ct

def countrhombi2(h, w):
	return h * h // 4 * (w * w // 4)

def binpow(a, b):
	if b == 0:
		return 1
	else:
		res = binpow(a, b // 2)
	if b % 2 != 0:
		return res * res * a
	else:
		return res * res

def binpowmodulus(a, b, m):
	a %= m
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b >>= 1
	return res

def coprime_to_n(n):
	result = n
	i = 2
	while i * i <= n:
		if n % i == 0:
			while n % i == 0:
				n //= i
			result -= result // i
		i += 1
	if n > 1:
		result -= result // n
	return result

def prime(x):
	if x == 1:
		return False
	else:
		for i in range(2, int(math.sqrt(x)) + 1):
			if x % i == 0:
				return False
		else:
			return True

def luckynumwithequalnumberoffourandseven(x, n, a):
	if x >= n and str(x).count('4') == str(x).count('7'):
		a.append(x)
	elif x < 1000000000000.0:
		luckynumwithequalnumberoffourandseven(x * 10 + 4, n, a)
		luckynumwithequalnumberoffourandseven(x * 10 + 7, n, a)
	return a

def luckynuber(x, n, a):
	p = set(str(x))
	if len(p) <= 2:
		a.append(x)
	if x < n:
		luckynuber(x + 1, n, a)
	return a
res = set()

def solve(p, l, a, b):
	if p > n or l > 10:
		return
	if p > 0:
		res.add(p)
	solve(p * 10 + a, l + 1, a, b)
	solve(p * 10 + b, l + 1, a, b)

def main():
	(n, k) = sep()
	a = lis()
	ll = []
	for i in range(k):
		ans = []
		ans.append(a[i])
		for i in range(1, n * k + 1):
			if len(ans) == n:
				break
			if i not in a and i not in ll:
				ans.append(i)
				ll.append(i)
		print(*ans)
main()


(n, k) = map(int, input().split())
totalList = []
for i in range(1, n + 1):
	totalList.append(i)
ans = []
idxList = [int(ch) for ch in input().split()]
for i in range(k):
	ans.append([idxList[i]])
for i in range(k):
	for j in range(1, n * k + 1):
		if len(ans[i]) == n:
			break
		if j not in idxList:
			ans[i].append(j)
			idxList.append(j)
for item in ans:
	for num in item:
		print(num, end=' ')
	print()


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
l = list()
bottom = 1
for i in range(k):
	print(a[i], end=' ')
	count = 0
	for j in range(bottom, n * k + 1):
		if j not in a:
			print(j, end=' ')
			count += 1
		if count == n - 1:
			print
			bottom = j + 1
			break
	print()


def children_to_slices(n, k, l):
	kid_to_slice = [[]] * (k + 1)
	remaining = set([i for i in range(1, n * k + 1)])
	for item in l:
		kid_to_slice[item[0]] = kid_to_slice[item[0]] + [item[1]]
		remaining.remove(item[1])
	for i in range(1, k + 1):
		while len(kid_to_slice[i]) < n:
			kid_to_slice[i] = kid_to_slice[i] + [remaining.pop()]
	return kid_to_slice
first_line = input().split()
n = int(first_line[0])
k = int(first_line[1])
l = []
assignments = [int(item) for item in input().split()]
for i in range(len(assignments)):
	l.append((i + 1, assignments[i]))
m = children_to_slices(n, k, l)
for i in range(1, k + 1):
	output = ''
	for item in m[i]:
		output += str(item) + ' '
	print(output)


def inp():
	return map(int, input().split())

def arr_inp():
	return [int(x) for x in input().split()]

def print_arr(arr):
	print(*arr, sep=' ')
(n, k) = inp()
a = arr_inp()
(extra, len, old, c) = ([], 0, 0, 0)
for i in range(1, n * k + 1):
	if i not in a:
		extra.append(i)
		len += 1
	if len > 0 and len % (n - 1) == 0 and (len > old):
		(ix1, ix2) = (c * (n - 1), len)
		print(a[c], end=' ')
		print_arr(extra[ix1:ix2])
		old = len
		c += 1
	if n == 1:
		print(a[i - 1])


(n, k) = map(int, input().split())
s = set()
for i in range(n * k + 1):
	s.add(i)
s.pop()
li = list(map(int, input().split()))
for i in range(k):
	s.remove(li[i])
for i in range(k):
	print(li[i], end=' ')
	for j in range(n - 1):
		print(s.pop(), end=' ')
	print()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
j = 0
for i in range(k):
	b.append(a[i])
	c = 0
	while c < n - 1:
		if j + 1 not in a:
			b.append(j + 1)
			c += 1
		j += 1
	print(*b)
	b = []
	c = 0


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
s = set(l)
val = [str(x) for x in range(1, n * k + 1) if x not in s]
di = {k: v for (k, v) in enumerate(l)}
for i in range(0, k):
	print(' '.join(val[i * (n - 1):(i + 1) * (n - 1)]) + f' {di[i]}')


(n, k) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = [0 for i in range(0, n * k)]
for i in l1:
	l2[i - 1] = 1
ch = 0
for i in range(0, k):
	print(l1[i], end=' ')
	j = 0
	while j < n - 1:
		if l2[ch] == 0:
			print(ch + 1, end=' ')
			ch = ch + 1
			j = j + 1
		else:
			ch = ch + 1
	print()


params = [int(item) for item in input().split()]
n = params[0]
k = params[1]
wants = [int(item) for item in input().split()]
temp = set(wants)
total = set(range(1, n * k + 1))
left = list(total - temp)
divide_left = len(left) / k
for i in wants:
	count = 0
	print(i, end=' ')
	while count < divide_left:
		print(left[0], end=' ')
		left.pop(0)
		count = count + 1


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
result = 1
for i in range(k):
	print(a[i], end=' ')
	counter = 0
	while counter != n - 1:
		if result in a:
			result += 1
		else:
			print(result, end=' ')
			counter += 1
			result += 1
	print('')


(n, k) = map(int, input().split())
a = list(range(1, n * k + 1))
ora = [[] for _ in ' ' * k]
for (i, j) in enumerate(map(int, input().split()), 0):
	ora[i].append(j)
	a.remove(j)
for i in ora:
	while len(i) < n:
		i.append(a.pop())
for i in ora:
	print(*i)


iarr = list(map(int, input().split()))
n = iarr[0]
k = iarr[1]
arr = list(map(int, input().split()))
flagar = [0 for i in range(n * k + 1)]
for i in arr:
	flagar[i] = 1
for i in range(k):
	arr[i] = [arr[i]]
count = 1
ind = 0
for i in range(1, n * k + 1):
	if count < n:
		if flagar[i] == 0:
			arr[ind].append(i)
			count += 1
	else:
		count = 1
		ind += 1
		if count < n:
			if flagar[i] == 0:
				arr[ind].append(i)
				count += 1
for i in range(k):
	for j in arr[i]:
		print(j, end=' ')
	print()


(n, k) = map(int, input().split())
L = list(map(int, input().split()))
Taken = [False] * (n * k + 1)
for item in L:
	Taken[item] = True
ind = 1
for i in range(k):
	cnt = 1
	print(L[i], end=' ')
	while cnt < n:
		while Taken[ind]:
			ind += 1
		print(ind, end=' ')
		ind += 1
		cnt += 1
	print()


(n, k) = [int(x) for x in input().split()]
likes = [int(x) for x in input().split()]
oranges = [True] * (n * k)
for i in likes:
	oranges[i - 1] = False
oranges_cnt = 0
for l in likes:
	print(l, end=' ')
	for _ in range(n - 1):
		while not oranges[oranges_cnt]:
			oranges_cnt += 1
		print(oranges_cnt + 1, end=' ')
		oranges_cnt += 1
	print()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
orange = [x for x in range(1, n * k + 1)]
seg = []
for i in range(k):
	seg.append([a[i]])
	orange.remove(a[i])
for i in range(k):
	while len(seg[i]) < n:
		seg[i].append(orange.pop())
	print(*seg[i])


(n, k) = [int(i) for i in input().split()]
data = [int(i) for i in input().split()]
box = [0 for i in range(n * k)]
(a, b) = (0, n * k)
for i in range(k):
	box[data[i] - 1] = 1
	print(data[i], end=' ')
	c = 1
	for j in range(a, b):
		if box[j] == 0 and c < n and (not j + 1 in data):
			print(j + 1, end=' ')
			box[j] = 1
			c += 1
		elif c == n:
			a = j
			break
	print()


def solve(arr, n, k):
	numbers = []
	res = []
	for i in range(1, n * k + 1):
		if i not in arr:
			numbers.append(i)
	i = 0
	for v in arr:
		print(v, *numbers[i:i + n - 1])
		i += n - 1

def main():
	(n, k) = list(map(int, input().split(' ')))
	arr = list(map(int, input().split(' ')))
	solve(arr, n, k)
main()


(n, k) = map(int, input().split())
compulsory = list(map(int, input().split()))
answer = [[] for _ in range(1000)]
mark = [False for _ in range(1000)]
for i in range(len(compulsory)):
	mark[compulsory[i]] = True
	answer[i].append(compulsory[i])
k1 = 0
j = 0
for i in range(1, n * k + 1):
	if mark[i]:
		continue
	answer[k1].append(i)
	j += 1
	if j % (n - 1) == 0:
		k1 += 1
for i in range(k):
	for temp in answer[i]:
		print(temp, end=' ')
	print()


(n, k) = list(map(int, input().split()))
l = list(range(1, n * k + 1))
d = {}
a = list(map(int, input().split()))
for i in range(len(a)):
	d[i] = [a[i]]
	l.remove(a[i])
for i in range((n - 1) * k):
	d[i % k] = d[i % k] + [l[i]]
for (k, v) in d.items():
	for i in v:
		print(i, end=' ')


(n, k) = map(int, input().split())
arr = [int(i) for i in input().split()]
res = [[i] for i in arr]
p = 0
for i in range(n * k):
	if i + 1 in arr:
		continue
	res[p].append(i + 1)
	p += 1
	if p >= k:
		p = 0
for i in res:
	print(*i)


(n, k) = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
num = [i for i in range(1, n * k + 1)]
nums = []
for i in num:
	if i not in arr:
		nums.append(i)
start = 0
for i in range(k):
	print(*nums[start:start + n - 1] + [arr[i]])
	start += n - 1


(n, k) = map(int, input().split())
arr = [int(i) for i in input().split()]
if n == 1:
	for i in arr:
		print(i)
	exit()
c = 1
for i in range(k):
	print(arr[i], end=' ')
	x = 0
	con = 1
	while con:
		if c not in arr:
			print(c, end=' ')
			x = x + 1
			if x == n - 1:
				con = 0
		c = c + 1
	print()


arr = input().split()
n = int(arr[0])
k = int(arr[1])
arr = input().split()
s = set()
for ch in arr:
	s.add(int(ch))
for ch in arr:
	print(ch, end=' ')
	ctr = 0
	ptr = 1
	while ctr < n - 1:
		if ptr not in s:
			print(str(ptr), end=' ')
			ctr += 1
			s.add(ptr)
		ptr += 1
	print('')


def main():
	[n, k] = [int(_) for _ in input().split()]
	likes = [int(_) for _ in input().split()]
	not_likes = [i for i in range(1, n * k + 1) if i not in likes]
	children = {}
	for i in range(k):
		left = i * (n - 1)
		right = left + n - 1
		children[i] = [likes[i]] + not_likes[left:right]
	for segments in children.values():
		print(' '.join([str(x) for x in segments]))
main()


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
s = 1
for i in range(k):
	p = n - 1
	print(l[i], end=' ')
	while p > 0:
		if s not in l:
			print(s, end=' ')
			p = p - 1
		s = s + 1
	print()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
i = 1
for j in range(k):
	r = [a[j]]
	while len(r) != n:
		if i in a:
			i += 1
		else:
			r.append(i)
			i += 1
	print(' '.join((str(r[z]) for z in range(n))))


(n, k) = list(map(int, input().split()))
req = list(map(int, input().split()))
req.append('fake')
idx = 0
ans = [req[0]]
hashSet = set(req)
for i in range(1, n * k + 1):
	if i not in hashSet:
		ans.append(i)
	if len(ans) == n:
		print(*ans)
		idx += 1
		ans = [req[idx]]


(n, k) = map(int, input().split())
b = [0] * (n * k)
c = []
count = 0
a = list(map(int, input().split()))
for i in range(1, n * k + 1):
	if i not in a:
		c.append(i)
for i in range(k):
	b[n * i] = a[i]
for i in range(n * k):
	if b[i] == 0:
		b[i] = c[count]
		count += 1
for i in range(n * k):
	if (i + 1) % n == 0:
		print(b[i])
	else:
		print(b[i], end=' ')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
a = [x for x in range(1, n * k + 1) if x not in l]
for x in range(k):
	print(l[x], *a[x * (n - 1):(x + 1) * (n - 1)])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = []
b = list(range(1, n * k + 1))
for i in range(k):
	ans.append([a[i]])
	b.remove(a[i])
for j in range(k):
	for k in range(n - 1):
		ans[j].append(b.pop(0))
for k in ans:
	print(*k)


(n, k) = map(int, input().split())
daf = list(map(int, input().split()))
daf2 = set()
for i in range(1, n * k + 1, 1):
	if i not in daf:
		daf2.add(i)
for i in range(k):
	has = [daf[i]]
	for j in range(n - 1):
		has.append(daf2.pop())
	print(*has)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
d = dict()
b = []
for i in range(len(l)):
	if i + 1 not in d:
		d[i + 1] = []
		d[i + 1].append(l[i])
for i in range(1, n * k + 1):
	if i not in l:
		b.append(i)
j = 1
count = 0
for i in range(len(b)):
	if count == n - 1:
		count = 0
		j += 1
	d[j].append(b[i])
	count += 1
for i in d:
	for j in range(len(d[i])):
		print(d[i][j], end=' ')
	print()


a = input().split(' ')
n = int(a[0])
k = int(a[1])
a = input().split(' ')
b = []
for i in range(k):
	a[i] = int(a[i]) - 1
	b.append(a[i])
b.sort()
d = {}
counter = 0
for i in range(k):
	d[i] = [a[i]]
	count = 0
	while count < n - 1:
		if counter not in b:
			d[i].append(counter)
			count = count + 1
			counter = counter + 1
		else:
			counter = counter + 1
for i in range(k):
	for j in d[i]:
		print(j + 1, end=' ')
	print()


(n, k) = input().strip().split(' ')
(n, k) = (int(n), int(k))
list1 = list(map(int, input().strip().split(' ')))
ls = [x for x in range(1, n * k + 1)]
for i in range(k):
	ls.remove(list1[i])
list2 = []
i = 0
j = 0
while j < k:
	print(*ls[i:i + n - 1] + [list1[j]])
	i += n - 1
	j += 1


import sys
In = sys.stdin
(n, k) = [int(x) for x in In.readline().split()]
(arr, s, cnt) = ([int(x) for x in In.readline().split()], set(), 1)
s.update(arr)
for i in range(k):
	c = [arr[i]]
	for j in range(n - 1):
		while cnt in s:
			cnt += 1
		c.append(cnt)
		cnt += 1
	sep = ' '
	print(sep.join(map(str, c)))


import math
import collections
from itertools import permutations
from itertools import combinations

def prob():
	(n, k) = [int(x) for x in input().split()]
	l = [int(x) for x in input().split()]
	ans = []
	for i in range(1, n * k + 1):
		if i not in l:
			ans.append(i)
	for i in range(k):
		print(l[i], *ans[i * (n - 1):(i + 1) * (n - 1)])
t = 1
for _ in range(0, t):
	prob()


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
vals = set(range(1, N * K + 1))
answer = [[] for k in range(K)]
for k in range(K):
	answer[k].append(A[k])
	vals.remove(A[k])
k = 0
while len(vals) > 0:
	answer[k].append(vals.pop())
	k = (k + 1) % K
for k in range(K):
	print(' '.join([str(x) for x in answer[k]]))


(n, k) = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
s = set(range(1, n * k + 1))
for ai in a:
	s.remove(ai)
for ai in a:
	print(ai, end='')
	for i in range(n - 1):
		print(' ' + str(s.pop()), end='')
	print()


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
set_ = set(l)
ans = [[i] for i in l]
i = 1
target = 0
while i < n * k + 1:
	if i in set_:
		i += 1
	elif len(ans[target]) < n:
		ans[target].append(i)
		i += 1
	else:
		target += 1
for i in ans:
	print(*i)


(n, k) = map(int, input().split())
l = [int(i) for i in input().split()]
l2 = [[i] for i in l]
p = 0
for i in range(n * k):
	if i + 1 in l:
		continue
	l2[p].append(i + 1)
	p += 1
	if p >= k:
		p = 0
for i in l2:
	print(*i)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
c = list(range(1, n * k + 1))
for i in range(k):
	b.append(a[i])
	c.remove(a[i])
m = 0
for i in range(k):
	print(b[i], end=' ')
	print(*c[m:m + n - 1])
	m += n - 1


(n, k) = map(int, input().split(' '))
a = list(input().split(' '))
s = set(a)
o = []
for i in range(k):
	o.append([a[i]])
for i in range(n * k):
	num = str(i + 1)
	j = 0
	if num not in s:
		while len(o[j]) == n:
			j += 1
		o[j].append(num)
for x in o:
	print(' '.join(x))


I = lambda : map(int, input().split())
(n, k) = I()
A = list(I())
X = set(range(1, n * k + 1)) - set(A)
for i in range(k):
	print(A[i], *(X.pop() for _ in range(n - 1)))


l1 = [int(x) for x in input().split()]
(n, k) = (l1[0], l1[1])
l2 = [int(x) for x in input().split()]
l3 = [x for x in range(1, n * k + 1) if x not in l2]
for x in range(len(l2)):
	c_out = [l2[x]]
	for y in range(n - 1):
		c_out.append(l3[-1])
		l3.pop()
	print(*c_out)


import sys
import math
(n, k) = [int(x) for x in sys.stdin.readline().split()]
an = [int(x) for x in sys.stdin.readline().split()]
k = [0] * (n * k)
for i in an:
	k[i - 1] = 1
j = 0
for i in an:
	v = []
	count = 0
	while count != n - 1:
		if k[j] != 1:
			v.append(str(j + 1))
			count += 1
		j += 1
	v.append(str(i))
	print(' '.join(v))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = {}
for x in range(k):
	d[x] = str(a[x])
u = [i for i in range(1, n * k + 1) if str(i) not in d.values()]
for x in range(n * k - k):
	d[x % k] += ' {}'.format(u[x])
for m in d:
	print(d[m])


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
a = [0] * (n * k + 1)
for i in range(k):
	a[l[i]] = i + 1
b = [[0] * n for i in range(k)]
for i in range(k):
	print(l[i], end=' ')
	j = 1
	s = 0
	while j < n * k + 1:
		if s == n - 1:
			break
		if a[j] == 0:
			print(j, end=' ')
			a[j] = -1
			s += 1
		j += 1
	print()


(n, k) = map(int, input().split())
a = [int(a) for a in input().split()]
start = 1
for i in range(k):
	count = 1
	print(a[i], end=' ')
	while start <= n * k:
		if start not in a:
			print(start, end=' ')
			count += 1
		if count == n:
			start += 1
			break
		start += 1
	print()


import math
from math import gcd, floor, sqrt, log

def iin():
	return int(input())

def sin():
	return input().strip()

def listin():
	return list(map(int, input().strip().split()))

def liststr():
	return list(map(str, input().strip().split()))

def ceill(x):
	return int(x) if x == int(x) else int(x) + 1

def ceilldiv(x, d):
	return x // d if x % d == 0 else x // d + 1

def LCM(a, b):
	return a * b // gcd(a, b)

def solve():
	(n, k) = listin()
	a = listin()
	z = [i for i in range(1, n * k + 1) if i not in a]
	temp = 0
	for j in range(k):
		print(a[j], end=' ')
		for i in range(temp, n + temp - 1):
			print(z[i], end=' ')
		temp += n - 1
		print()
t = 1
for hula in range(t):
	solve()


(n, k) = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
children = {}
for (index, number) in enumerate(a):
	children[index + 1] = [number]
next_child = 1
for i in range(1, n * k + 1):
	if i not in a:
		if len(children[next_child]) == n:
			next_child += 1
		children[next_child].append(i)
for child in range(1, k + 1):
	print(*children[child])


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
ans = [[x] for x in a]
ptr = 0
for i in range(n * k):
	i += 1
	if i in a:
		continue
	ans[ptr].append(i)
	ptr += 1
	if ptr >= k:
		ptr = 0
print('\n'.join((' '.join((str(x) for x in l)) for l in ans)))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
i = 1
for x in a:
	ans = [x]
	while len(ans) != n:
		while i in a:
			i += 1
		ans.append(i)
		i += 1
	print(*ans)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
var = 1
for i in range(k):
	cnt = 1
	print(arr[i], end=' ')
	while cnt != n:
		if var not in arr:
			print(var, end=' ')
			cnt = cnt + 1
		var = var + 1
	print('\n', end='')


(n, k) = map(int, input().split())
ai = list(map(int, input().split()))
free = list(set([i for i in range(1, n * k + 1)]) - set(ai))
n2 = n - 1
for i in range(k):
	print(ai[i], end=' ')
	print(' '.join(list(map(str, free[n2 * i:n2 * (i + 1)]))))


(n, k) = [int(i) for i in input().split()]
s = set(range(1, n * k + 1))
a = [set([int(i)]) for i in input().split()]
for aa in a:
	s -= aa
for i in range(k):
	for j in range(n - len(a[i])):
		a[i].add(s.pop())
	print(' '.join([str(j) for j in list(a[i])]))


(n, k) = map(int, input().split())
z = list(map(int, input().split()))
x = [int(i) for i in range(1, n * k + 1) if int(i) not in z]
a = 0
for i in range(k):
	print(z[i], end=' ')
	for j in range(a, a + n - 1):
		print(x[j], end=' ')
	a = a + n - 1
	print()


I = lambda : map(int, input().split())
(n, k) = I()
b = (*I(),)
exec('r=[' + k * '[],' + ']')
for (i, x) in enumerate(b):
	r[i] += [x]
i = 0
for j in range(1, n * k + 1):
	if j in b:
		continue
	while len(r[i]) == n:
		i += 1
	r[i] += [j]
for i in range(k):
	print(*r[i])


(n, k) = map(int, input().split())
b = [0 for i in range(n * k)]
a = list(map(int, input().split()))
for i in range(k):
	b[a[i] - 1] = i + 1
count = 0
c = 1
for i in range(n * k):
	if b[i] == 0:
		count += 1
		b[i] = c
	if count == n - 1:
		count = 0
		c += 1
for i in range(k):
	for j in range(n * k):
		if b[j] == i + 1:
			print(j + 1, end=' ')
	print('')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = [[] for i in range(0, k + 1)]
u = [0] * (n * k + 1)
for i in range(k):
	b[i].append(a[i])
	u[a[i]] = 1
p = 0
for i in range(1, n * k + 1):
	if u[i] == 0:
		u[i] = 1
		b[p].append(i)
	if len(b[p]) == n:
		p += 1
for i in range(k):
	for j in range(n):
		print(b[i][j], end=' ')
	print()


row = input()
n = int(row.split()[0])
k = int(row.split()[1])
row1 = input()
selected = [x for x in row1.split()]
for i in range(0, len(selected)):
	selected[i] = int(selected[i])
notselected = [x for x in range(1, n * k + 1) if x not in selected]
idx = 0
for i in range(k):
	print(selected[i], end=' ')
	for j in range(n - 1):
		print(notselected[idx], end=' ')
		idx = idx + 1
	print('\n')


def main():
	(n, k) = [int(i) for i in input().split()]
	s = list(range(1, n * k + 1))
	arr = [int(i) for i in input().split()]
	plist = []
	for i in arr:
		s.remove(i)
	for i in arr:
		plist.append([i] + s[:n - 1])
		s[:] = s[n - 1:]
	for i in plist:
		print(*i)
	return 0
main()


n = input()
(n, k) = n.split()
n = int(n)
k = int(k)
i = input()
numeros = []
numeros = i.split()
for i in range(k):
	numeros[i] = int(numeros[i])
laranja = [-1 for i in range(n * k + 1)]
for i in range(k):
	laranja[numeros[i]] = i
count = n - 1
for i in range(k):
	for j in range(1, n * k + 1):
		if laranja[j] == -1:
			laranja[j] = i
			count -= 1
		if count == 0:
			count = n - 1
			break
for j in range(k):
	for i in range(1, n * k + 1):
		if laranja[i] == j:
			print(i, ' ', end='')
	print()


[n, k] = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
arr = list(range(1, n * k + 1))
for i in a:
	arr.remove(i)
j = 0
for i in a:
	print(i, *arr[j:j + n - 1])
	j = j + n - 1


import sys
ioRead = sys.stdin.readline
ioWrite = lambda x: sys.stdout.write(f'{x}\n')
(n, k) = map(int, ioRead().split(' '))
l = [-1 for _ in range(n * k)]
ol = list(map(int, ioRead().split(' ')))
for o in ol:
	l[o - 1] = 1
i = 0
for c in range(k):
	printable = [str(ol[c])]
	for _ in range(n - 1):
		while l[i] == 1:
			i += 1
		l[i] = 1
		i += 1
		printable.append(str(i))
	ioWrite(' '.join(printable))


(n, k) = list(map(int, input().split(' ')))
x = list(map(int, input().split(' ')))
a = [False for i in range(n * k)]
for i in range(k):
	a[x[i] - 1] = True
j = 0
for i in range(k):
	print(x[i], end=' ')
	k = 0
	while k < n - 1:
		if a[j] == False:
			print(j + 1, end=' ')
			a[j] = True
			k += 1
		j += 1
	print()


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
j = 1
for i in range(k):
	l = [a[i]]
	while len(l) != n:
		if j not in a:
			l.append(j)
		j += 1
	l.sort()
	print(*l)


(N, K) = map(int, input().strip().split())
A = list(map(lambda a: int(a) - 1, input().strip().split()))
selected = [False for _ in range(N * K)]
for i in range(len(A)):
	selected[A[i]] = True
for i in range(K):
	segs = [A[i] + 1]
	for j in range(1, N):
		for ii in range(len(selected)):
			if not selected[ii]:
				selected[ii] = True
				segs += [ii + 1]
				break
	print(*segs)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
i = 1
for j in range(k):
	temp = [a[j]]
	while len(temp) != n:
		if i in a:
			i += 1
		else:
			temp.append(i)
			i += 1
	print(' '.join((str(temp[m]) for m in range(n))))


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
(n, k) = get_int_list()
lst = get_int_list()
nk = list(range(1, n * k + 1))
for i in range(k):
	nk.remove(lst[i])
matrix = [[lst[i]] for i in range(k)]
for i in range(k):
	start = i * (n - 1)
	end = (i + 1) * (n - 1)
	matrix[i].extend(nk[start:end])
for i in range(k):
	print(*matrix[i])


def con(n):
	p = []
	for s in n:
		s = str(s)
		p.append(s)
	return ' '.join(p)
(n, k) = input().split()
n = int(n)
k = int(k)
a = list(map(int, input().split()))
i = 0
l = []
for s in range(n * k + 1):
	if s not in a and s != 0:
		l.append(s)
while i < k:
	z = []
	j = 0
	while len(z) < n - 1:
		z.append(l[j])
		l.pop(j)
	z.append(a[i])
	print(con(z))
	i += 1


from collections import defaultdict
(n, k) = map(int, input().split())
mul = n * k
arr = list(map(int, input().split()))
visited = defaultdict(bool)
total = []
for i in range(k):
	visited[arr[i]] = True
	total.append([arr[i]])
x = 0
for i in range(1, mul + 1):
	if len(total[x]) == n:
		x += 1
	if x == k:
		break
	if not visited[i]:
		total[x].append(i)
for i in range(len(total)):
	print(*total[i])


(n, k) = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]
res_arr = [[] for i in range(k)]
free = [True] * (n * k + 1)
for (ind, v_a) in enumerate(a):
	res_arr[ind].append(v_a)
	free[v_a] = False
ind = 0
for i in range(1, n * k + 1):
	if free[i]:
		if len(res_arr[ind]) == n:
			ind += 1
		res_arr[ind].append(i)
		free[i] = False
for i in range(k):
	print(*res_arr[i], sep=' ')


(n, k) = map(int, input().split())
L = list(map(int, input().split()))
Explored = [False] * (n * k + 1)
Ans = []
for i in range(k):
	Ans.append([])
for i in range(k):
	Ans[i].append(L[i])
	Explored[L[i]] = True
ind = 0
for i in range(1, n * k + 1):
	if Explored[i]:
		continue
	Ans[ind].append(i)
	ind += 1
	if ind >= k:
		ind = 0
for i in range(k):
	print(Ans[i][0], end='')
	for j in range(1, n):
		print(' ' + str(Ans[i][j]), end='')
	print()


(n, k) = [int(c) for c in input().split()]
segments = [int(c) for c in input().split()]
segments_set = set(segments)
pool = [i for i in range(1, k * n + 1) if i not in segments_set]
for s in segments:
	res = [s] + [pool.pop() for _ in range(n - 1)]
	print(*res)


(n, k) = [int(i) for i in input().split()]
segment = list(range(1, n * k + 1))
for i in range(n * k):
	segment[i] = str(segment[i])
num = [int(i) for i in input().split()]
for i in num:
	segment.remove(str(i))
t = 0
for i in num:
	print(i, ' '.join(segment[t:t + n - 1]))
	t += n - 1


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l1 = {i for i in range(1, n * m + 1)}
for x in l:
	out = []
	out.append(x)
	l1.remove(x)
	j = 1
	ch = []
	for x1 in l1:
		if x1 not in l:
			if j != n:
				j += 1
				out.append(x1)
				ch.append(x1)
			else:
				break
	for x1 in ch:
		l1.remove(x1)
	print(' '.join(map(str, out)))


(n, k) = map(int, input().split())
L = list(map(int, input().split()))
S = []
for i in range(k):
	S.append([])
ind = 0
for i in range(1, n * k + 1):
	if i in L:
		x = L.index(i)
		S[x].append(i)
	else:
		S[ind].append(i)
		ind += 1
		if ind == k:
			ind = 0
for i in range(k):
	for j in range(n):
		print(S[i][j], end=' ')
	print()


(n, k) = [int(x) for x in input().split()]
l = list(map(int, input().split()))
m = n * k
p = []
for i in range(1, m + 1):
	if i not in l:
		p.append(i)
f = int(0)
for i in range(0, k):
	ans = []
	ans.append(l[i])
	if f < len(p):
		for j in range(0, n - 1):
			ans.append(p[f])
			f = f + 1
	print(*ans, end='\n')


ar = []
for i in input().split():
	ar.append(int(i))
ar2 = []
for i in input().split():
	ar2.append(int(i))
temp = list(set(range(1, ar[0] * ar[1] + 1)) - set(ar2))
for i in range(len(ar2)):
	res = []
	res.append(ar2[i])
	while len(res) != ar[0]:
		res.append(temp[0])
		temp.pop(0)
	print(*res)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in range(1, n * k + 1):
	b.append(i)
for i in a:
	b[i - 1] = 0
t = 0
for i in range(k):
	print(a[i], end=' ')
	p = n - 1
	while p > 0:
		if b[t] > 0:
			print(b[t], end=' ')
			p -= 1
		t += 1
	print()


from sys import stdin, stdout

def solve():
	(n, k) = map(int, stdin.readline().split())
	li = list(map(int, stdin.readline().split()))
	vis = [-1 for i in range(n * k)]
	for i in range(k):
		vis[li[i] - 1] = i
	ans = [list() for i in range(k)]
	p = 0
	for i in range(n * k):
		if vis[i] < 0:
			ans[p].append(i + 1)
			p += 1
			p %= k
		else:
			ans[vis[i]].append(i + 1)
	for l in ans:
		for e in l:
			print(e, end=' ')
		print()
LOCAL_TEST = not __debug__
if LOCAL_TEST:
	infile = __file__.split('.')[0] + '-test.in'
	stdin = open(infile, 'r')
tcs = int(stdin.readline().strip()) if LOCAL_TEST else 1
t = 1
while t <= tcs:
	solve()
	t += 1


a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ranges = [int(i) for i in range(1, a[0] * a[1] + 1)]
for i in b:
	ranges.remove(i)
j = 0
for i in range(a[1]):
	d = []
	d.append(str(b[i]))
	while len(d) < a[0]:
		d.append(str(ranges[j]))
		j += 1
	print(' '.join(d))


(X, Segments) = (list(map(int, input().split())), list(map(int, input().split())))
PickedSegments = [False for i in range(X[0] * X[1])]
for i in range(X[1]):
	PickedSegments[Segments[i] - 1] = True
j = 0
for i in range(X[1]):
	print(Segments[i], end=' ')
	for k in range(X[0] - 1):
		while PickedSegments[j]:
			j += 1
		PickedSegments[j] = True
		print(j + 1, end=' ')
	print()


(n, k) = map(int, input().split())
l = [None] * (n * k)
l1 = list(map(int, input().split()))
for i in range(0, n * k, n):
	l[i] = l1[i // n]
for i in range(1, n * k + 1):
	if i in l1:
		continue
	else:
		l[l.index(None)] = i
for i in range(k):
	for j in range(n * i, n * i + n, 1):
		print(l[j], end=' ')
	print()


(n, k) = map(int, input().split())
prefer = list(map(int, input().split()))
S = [1] * (n * k)
children = []
for p in prefer:
	children += [[p - 1]]
	S[p - 1] = 0
children = children[::-1]
for (i, s) in enumerate(S):
	if len(children) == 0:
		break
	if len(children[-1]) == n:
		for c in children[-1]:
			print(c + 1, end=' ')
		children.pop()
		print()
	if s == 1:
		children[-1].append(i)
		if len(children[-1]) == n:
			for c in children[-1]:
				print(c + 1, end=' ')
			children.pop()
			print()


in1 = [int(i) for i in input().split()]
(n, k) = (in1[0], in1[1])
segments = input()
a = [int(x) for x in segments.split()]
r = [[0 for i in range(n)] for j in range(k)]
indexes = [i + 1 for i in range(n * k)]
filtered = list(filter(lambda x: x not in a, indexes))
for i in range(k):
	r[i] = filtered[i * (n - 1):i * (n - 1) + n - 1]
	r[i].append(a[i])
for i in range(k):
	print(*r[i])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
total = [i + 1 for i in range(n * k)]
answers = [()] * k
for i in range(k):
	answers[i] += (a[i],)
	total.remove(a[i])
(sikandar, count, lolo, j) = (len(total) / k, 0, tuple(), 0)
for i in total:
	lolo += (i,)
	count += 1
	if count == sikandar:
		answers[j] += lolo
		j += 1
		lolo = tuple()
		count = 0
for i in answers:
	print(*list(i), end='\n')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
c = []
for i in range(k):
	print(a[i], end=' ')
	l = 1
	for j in range(1, n * k + 1):
		if j not in a and j not in c and (l < n):
			print(j, end=' ')
			l += 1
			c.append(j)
		if l >= n:
			l = 1
			break
	print()


import sys
f = sys.stdin
(n, k) = map(int, f.readline().strip().split())
a = [int(i) for i in f.readline().strip().split()]
num = [True] * n * k
for i in a:
	num[i - 1] = False
for i in a:
	print(i, end=' ')
	cnt = 1
	for j in range(1, n * k + 1):
		if cnt < n:
			if num[j - 1]:
				num[j - 1] = False
				print(j, end=' ')
				cnt += 1
		else:
			break
	print()


(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
s = [[0] * n for _ in range(k)]
for j in range(k):
	s[j][0] = a[j]
nk = 1
for i in range(k):
	for j in range(1, n):
		while nk in a:
			nk = nk + 1
		s[i][j] = nk
		nk = nk + 1
for i in range(k):
	for j in range(n):
		print(s[i][j], end=' ')


(n, k) = map(int, input().split())
res = [[] for _ in range(k)]
used = set()
for (i, val) in enumerate(input().split()):
	val = int(val)
	used.add(val)
	res[i].append(val)
i = 0
for val in range(1, n * k + 1):
	if val in used:
		continue
	while len(res[i]) == n:
		i += 1
	res[i].append(val)
for i in res:
	print(*i)