#include using std::cin; using std::cout; using std::endl; using std::vector; int main(){ int N,M; cin>>N>>M; const int max=1e5,inf=1e9; assert(1<=N&&N<=max&&1<=M&&M<=max); vector A(N); int ans=0,sum=0; std::set set; set.insert(M); for(int i=0;i>A[i]; assert(1<=A[i]&&A[i]<=inf); sum+=A[i]%M; sum%=M; ans=std::max(ans,sum+M-*set.upper_bound(sum)); set.insert(sum); } cout<