n,m=map(int, input().split())
odd=[]
absent=[]
l=list(map(int, input().split()))
for i in range(n):
    ind=[0]*(m+1)
    for j in range(m*i, m*(i+1)):
        a=l[j]
        ind[a]+=1
        if ind[a]==2:
            odd.append([a, j+1])
    d=-1
    for j in range(1, m+1):
        if ind[j]==0:
            absent.append([j, odd[d][1]])
            d-=1

ans=[]
ind=0
o=odd[ind]
free=o
a=o[1]
b=n*m+1
free[1]=b
ans.append([a,b])
seen=[False]*len(odd)
while free!=None:
    ab=absent[ind]
    seen[ind]=True
    o=None
    for i in range(len(odd)):
        if odd[i][0]==ab[0] and seen[i]==False:
            o=odd[i]
            ind=i
            break
    if o==None:
        o=free
        free=None
    a=o[1]
    b=ab[1]
    ans.append([a,b])

print(len(ans))
for i in range(len(ans)):
    print(ans[i][0], ans[i][1])