#include using namespace std; typedef long long ll; const int MOD = 1000000007; const int INF = 1000000000; #define REP(i,n) for((i)=0;(i)<(int)(n);(i)++) int n; int a[20]; ll func(int x){ ll ret = 0; for (int i = 0; i < n; i++){ ret += abs(a[i] - x); } return ret; } int main(){ int b; cin >> b >> n; for (int i = 0; i < n; i++) cin >> a[i]; int ng = -1; int ok = INF; while(abs(ok - ng) > 1){ int mid = (ok + ng) / 2; if (func(mid) <= func(mid + 1)) ok = mid; else ng = mid; } cout << func(ok) << endl; return 0; }