def readList():
    return [int(i) for i in input().split()]

n, m = readList()
a = readList()
ans = []
ind = 0
while ind < n * m:
	#print(a)
	cur = [0] * (m + 1)
	double = []
	step = 0
	while step < m:
		#print(cur)
		if cur[a[ind + step]]:
			double.append(ind + step)
		cur[a[ind + step]] = 1
		step += 1
	#print(double, cur)
	doubleIndd = 0
	for i in range(1, m + 1):
		if cur[i] == 1:
			continue
		#print(i, ind)
		indexC = a[ind:].index(i) + ind
		doubleInd = double[doubleIndd]
		ans.append([doubleInd + 1, n * m + 1])
		ans.append([indexC + 1, doubleInd + 1])
		ans.append([doubleInd + 1, indexC + 1])
		a[doubleInd], a[indexC] = a[indexC], a[doubleInd]
		doubleIndd += 1
	ind += step
#print(a)
print(len(ans))
for x in ans:
	print(*x)