quernums,x=map(int,input().split( ))
mex=0
array0=[]
import bisect
def indexmin(item,array):
    if item>=array[-1]:
        return len(array)
    elif item<array[0]:
        return 0
    start=0
    end=len(array)-1
    while start<=end:
        midpoint=(start+end)//2
        if abs(start-end)<=1:
            return midpoint+1
        elif item<array[midpoint]:
            end=midpoint
        elif item>=array[midpoint]:
            start=midpoint
    return len(array)

def index(item, array):
    start=0
    end=len(array)-1
    while start<=end:
        midpoint=(start+end)//2
        if array[midpoint]==item:
            return [True,midpoint]
        elif item<array[midpoint]:
            end=midpoint-1
        elif item>=array[midpoint]:
            start=midpoint+1
    return [False]

for b in range(quernums):
    query=int(input())
    if b==0:
        array0.append(b)
    else:
        array0.insert(indexmin(query,array0),query)
    if query==mex:
        mex+=1
    repeats=0
    biggerthan=0
    if index(mex+3,array0)[0]==True:
        mex+=1
    elif index(mex-3,array0)[0]==True:
        if array0[index(mex-3,array0)[1]]==array0[index(mex-3,array0)[1]+1]:
            mex+=1
    if b<=quernums-2:
        print(mex)
array0.sort()
remainderlist=[0 for a in range(x)]
for k in array0:
    remainder=k%x
    remainderlist[k%x]+=1
minremainder=min(remainderlist)
indexofremainder=remainderlist.index(minremainder)
minnum=0
minnum+=x*minremainder+indexofremainder
print(minnum)