#include<bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<n;i++) #define ll long long int main(){ int b,n; ll ans=0,l,ave=0; cin >> b >> n; vector<int> c(n); REP(i,n) cin >> c[i],ave+=c[i]; ave+=b;ave/=n; sort(c.begin(),c.end()); if(n%2!=0) l=c[n/2]; else l=(c[n/2-1]+c[n/2])/2; l=min(ave,l); REP(i,n) ans+=abs(l-c[i]); cout << ans << endl; return 0; }