import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int B = sc.nextInt(); int N = sc.nextInt(); int[] C = new int[N]; for (int i = 0; i < C.length; i++) { C[i] = sc.nextInt(); } sc.close(); long min = Long.MAX_VALUE; for (int i = 0; i < C.length; i++) { long V = C[i]; long sum = B; for (int j = 0; j < C.length; j++) { sum += C[j]; } if (sum < N * V) { V = sum / N; } long stock = B; long ope = 0; for (int j = 0; j < C.length; j++) { // 取り上げ stock += Math.max(0, C[j] - V); ope += Math.max(0, C[j] - V); } for (int j = 0; j < C.length; j++) { // 配る stock -= Math.max(0, V - C[j]); ope += Math.max(0, V - C[j]); } min = Math.min(min, ope); } System.out.println(min); } }