#include #include #include #include #include #include #include #include #include #include using namespace std; const int MAX= 10000100; #define loop(i,a,b) for(int i = a ; i < b ; i ++) #define rep(i,a) loop(i,0,a) #define all(a) (a).begin(),(a).end() #define ll long long int #define gcd(a,b) __gcd(a,b) #define pb(a) push_back(a) int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);} int lcm(int a, int b) {return a*b / gcd(a, b);} int main(void){ int b; int n; cin>>b>>n; vector c(n); int sum = 0; rep(i,n){ cin>>c[i]; sum += c[i]; } int ave = sum / n; sum = 0; int res = int(1e9); rep(i,n){ sum += abs(c[i] - ave); } res = sum; ave ++; rep(i,n){ sum += abs(c[i] - ave); } rep(i,b/n){ sum = 0; ave = ave + i - 1; sum = 0; rep(i,n){ sum += abs(c[i] - ave); } res = sum; ave ++; rep(i,n){ sum += abs(c[i] - ave); } sum = 0; res = min(res,sum); } cout<