import java.util.Scanner; public class HelloWorld { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int[] ai_Array = new int[n]; for (int i = 0; i < n; i ++) { ai_Array[i] = sc.nextInt(); } sc.close(); double sum_all = 0; int sum_bit = 0; for (int i = n - 1; i >= 0; i -- ) { sum_all += ai_Array[i] * Math.pow(k , n - 1 - i); sum_bit += ai_Array[i]; } System.out.println((int)sum_all%sum_bit ); } }