import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int b = sc.nextInt(); int n = sc.nextInt(); int[] arr = new int[n]; long sum = b; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); sum += arr[i]; } Arrays.sort(arr); long count = Math.min(arr[(n - 1) / 2], sum / n); long ans = 0; for (int x : arr) { ans += Math.abs(count - x); } System.out.println(ans); } }