#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ull = unsigned long long; using ll = long long; int main() { int n,m; cin >> n >> m; vector data(20002); vector indexs(m); for(int i = 0; i < m; ++i) { int n; cin >> n; data.at(10000 + n) = 1; indexs.at(i) = n; } indexs.emplace_back(0); sort(indexs.begin(),indexs.end()); int minimum = 1000000; for(auto&& x : indexs) { if(x > 0) break; int count = 0; int s = 0; // if(x < 0) // s = abs(x); bool check = false; for(int i = 10000 + x; i < data.size(); ++i) { if(data.at(i) == 1) ++count; if(count == n) { if(i >= 10001) s+=abs(x); check = true; break; } ++s; } if(check) minimum = min(minimum,s); check = false; } cout << minimum<< endl; }