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]; long sum = 0; long sum_bit = 0; for (int i = 0; i < n; i ++) { ai_Array[i] = sc.nextInt(); sum_bit += ai_Array[i]; } sc.close(); for (int i = 0; i < n; i ++ ) { sum = sum * k + ai_Array[i]; sum %= k; } System.out.println(sum); } }