import java.util.*; public class Exercise88{ public static void main (String[] args){ Scanner sc = new Scanner(System.in); long h = sc.nextInt(); int n = sc.nextInt(); long[] box = new long[n]; long sum = 0; long ave = 0; for(int i = 0; i < n; i++){ box[i] = sc.nextInt(); sum += box[i]; } sum += h; Arrays.sort(box); ave = sum / (long)n; ave = Math.min(sum / n, box[n / 2]); long answer = 0; for(int i = 0; i < box.length; i++){ long x = box[i] - ave; if(x == 0){ continue; }else if(x < 0){ answer += x * -1; }else{ answer += x; } } System.out.println(answer); } }