use std::io::*; use std::cmp; fn main() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let b: isize = itr.next().unwrap().parse().unwrap(); let n: usize = itr.next().unwrap().parse().unwrap(); let mut c: Vec = itr.map(|e| e.parse().unwrap()).collect(); c.sort(); let med = if n % 2 == 0 { (c[n / 2] + c[n / 2 - 1]) / 2 } else { c[n / 2] }; let s: isize = c.iter().sum(); let x = cmp::min((b + s) / n as isize , med); let mut ans = 0; for i in 0..n { ans += (x - c[i]).abs(); } println!("{}", ans); }