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(); } long ans = Long.MAX_VALUE; for (int i = 0; i < c.length; i++) { int d = c[i]; int bb = b; long cnt = 0; for (int j = 0; j < c.length; j++) { cnt += Math.abs(c[j]-d); bb -= d-c[j]; } if(bb < 0)continue; ans = Math.min(ans, cnt); } System.out.println(ans); } }