quernums,x=map(int,input().split( ))
mex=0
array0=[]
import bisect
def index1(item, array):
    i=bisect.bisect_left(array,item)
    if i:
        return [True,i]
    return [False]
for b in range(quernums):
    query=int(input())
    if b==0:
        array0.append(query)
    else:
        bisect.insort_left(array0,query)
    if query==mex:
        mex+=1
    repeats=0
    biggerthan=0
    if index1(mex+3,array0)[0]==True:
        mex+=1
    elif index1(mex-3,array0)[0]==True:
        if array0[index1(mex-3,array0)[1]]==array0[index1(mex-3,array0)[1]+1]:
            mex+=1
    if b<=quernums-2:
        print(mex)
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)