import java.util.Arrays; import java.util.Scanner; /** * Created by poly on 11/29/14. */ public class Main { public static void main(String[] argv) { Scanner scanner = new Scanner(System.in); int b = scanner.nextInt(); int n = scanner.nextInt(); int[] c = new int[n]; int total = 0; for (int i = 0; i < n; i++) { c[i] = scanner.nextInt(); total += c[i]; } total += b; int max = total / n; Arrays.sort(c); long ans = 0; for (int j = 0; j < n; j++) { ans += Math.abs(c[j] - max); } for (int i = 0; i < n; i++) { long tmp = 0; for (int j = 0; j < n; j++) { tmp += Math.abs(c[j] - c[i]); } ans = Math.min(tmp, ans); } System.out.println(ans); } }