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