import java.io.*; import java.util.*; public class Main{ public static void main(String[] args) { var sc = new Scanner(System.in); var ou = new PrintWriter(System.out); int n = Integer.parseInt(sc.next()); int k = Integer.parseInt(sc.next()); long x = 0; long y = 0; for(int i = 0 ; i < n ; i++){ int a = Integer.parseInt(sc.next()); x *= k; x += a; y += a; } ou.println(x % y); sc.close(); ou.flush(); } }