n,k = map(int,input().split()) ns=list(map(int,input().split())) nssum=sum(ns) def n_t(X,n): t = 0 cnt=0 for i in range(len(X)-1,-1,-1): t += X[cnt]*(n**i) cnt+=1 return t ns10 = n_t(ns,k) print(ns10%nssum)