package main import ( "bufio" "fmt" "math" "os" "strconv" ) var sc = bufio.NewScanner(os.Stdin) var rdr = bufio.NewReaderSize(os.Stdin, 1000000) func main() { sc.Split(bufio.ScanWords) b, n := nextInt(), nextInt() boxes := make([]int, n) for i := 0; i < n; i++ { boxes[i] = nextInt() } sum := b for _, v := range boxes { sum += v } avg := sum / n min := int(1e16) for _, base := range boxes { c := 0 if base >= avg { continue } for _, v := range boxes { diff := int(math.Abs(float64(base - v))) c += diff } if c < min { min = c } } fmt.Println(min) } func nextLine() string { sc.Scan() return sc.Text() } func nextInt() int { i, _ := strconv.Atoi(nextLine()) return i }