// author: over_flow
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(iter) (iter).begin(), (iter).end()
#define mp make_pair
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define arin(vect) for (int i = 0; i < (vect).size(); i++) cin >> (vect)[i];
const char el = '\n';
const long double PI = acos((long double)-1);
const double Pi = acos((double)-1);
constexpr int pct(int x) { return __builtin_popcount(x); }

struct show {
#ifdef NATURE_VALLEY
    template<typename V, typename T>
    static void d(V name,T begin,T end){cerr<<"DEBUG: "<<name<<" = [";while(begin!=end)
        {cerr<<(*begin);++begin;if(begin!=end)cerr<<", ";}cerr<<"]\n";}
    template<typename V, typename T>
    static void dm(V name,T begin,T end){cerr<<"DEBUG: "<<name<<" = {\n";while(begin!=end)
        {cerr<<"  ["<<begin->first<<": "<<begin->second<<"],\n";++begin;}cerr<<"}\n";}
    template<typename V, typename T>
    static void debug(V name, T value){cerr<<"DEBUG: ("<<name<<" = "<<value<<")\n";}
#else
    template<typename V,typename T>
    static void d(V name,T begin,T end){}
    template<typename V,typename T>
    static void dm(V name,T begin,T end){}
    template<typename V, typename T>
    static void debug(V name, T value){}
#endif
}; // struct show
#define showd(var) show::d(#var, all(var))
#define showdm(var) show::dm(#var, all(var))
#define debug(var) show::debug(#var, var)

void solve() {
    int n;
    cin >> n;
    vector<int> ar(n);
    arin(ar);
    unordered_set<int> s;
    s.reserve(n);
    s.insert(all(ar));
    vector<int> other;
    other.reserve(n);
    for (int i = 1; i <= n; i++) {
        if (s.find(i) == s.end()) other.pb(i);
    }
    for (int i = 0; i < n; i++) {
        if (s.find(ar[i]) == s.end()) {
            ar[i] = other.back();
            other.pop_back();
        } else {
            s.erase(ar[i]);
        }
    }
    for (int i = 0; i < n; i++) {
        cout << ar[i] << " ";
    }
    cout << el;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    // READ THE PROBLEM STATEMENT
    // int t; cin >> t; while (t--)
        solve();

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 100005;

int a[N],freq[N];

/* Essa estrutura é nova pra alguns, será detalhada mais a frente.
    Mas adiantando, um vector é um array dinâmico, que não precisa ser declarado o tamanho, quando quisermos inserir um elemento, ele é inserido no final.
*/
vector <int> not_used;

int main(){
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        //incrementa a frequência do número lido
        freq[a[i]]++;
    }
    for(int i=1;i<=n;i++){
        //se a frequência de i for 0, ele não foi usado
        //para adicionar em um vector, basta dar push_back(x), onde x é o elemento a ser adicionado
        if(freq[i] == 0) not_used.push_back(i);
    }
    for(int i=1;i<=n;i++){
        //se não tiver mas nenhum número não sendo usado, a permutação está feita
        if(not_used.size() == 0) break;
        //se a frequência daquele número for maior que 1, precisamos trocá-lo, ou também se o número do a[i] for maior que n
        if(freq[a[i]] > 1 or a[i] > n){
            //diminui a frequência do número que vamos trocar
            freq[a[i]]--;
            //atribui àquele número repetido, o valor de um não usado
            a[i] = not_used.back();
            //remove o não usado da lista
            not_used.pop_back();
        }
    }
    //saída
    for(int i=1;i<=n;i++) cout << a[i] << " ";
    cout << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 100005;

int a[N],freq[N];

/* Essa estrutura é nova pra alguns, será detalhada mais a frente.
    Mas adiantando, um vector é um array dinâmico, que não precisa ser declarado o tamanho, quando quisermos inserir um elemento, ele é inserido no final.
*/
vector <int> not_used;

int main(){
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        //incrementa a frequência do número lido
        freq[a[i]]++;
    }
    for(int i=1;i<=n;i++){
        //se a frequência de i for 0, ele não foi usado
        //para adicionar em um vector, basta dar push_back(x), onde x é o elemento a ser adicionado
        if(freq[i] == 0) not_used.push_back(i);
    }
    for(int i=1;i<=n;i++){
        //se não tiver mas nenhum número não sendo usado, a permutação está feita
        if(not_used.size() == 0) break;
        //se a frequência daquele número for maior que 1, precisamos trocá-lo, ou também se o número do a[i] for maior que n
        if(freq[a[i]] > 1 or a[i] > n){
            //atribui àquele número repetido, o valor de um não usado
            a[i] = not_used.back();
            //remove o não usado da lista
            not_used.pop_back();
            //diminui a frequência do número que acabamos de trocar
            freq[a[i]]--;
        }
    }
    //saída
    for(int i=1;i<=n;i++) cout << a[i] << " ";
    cout << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 100005;

int a[N],freq[N];

/* Essa estrutura é nova pra alguns, será detalhada mais a frente.
    Mas adiantando, um vector é um array dinâmico, que não precisa ser declarado o tamanho, quando quisermos inserir um elemento, ele é inserido no final.
*/
vector <int> not_used;

int main(){
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        //incrementa a frequência do número lido
        freq[a[i]]++;
    }
    for(int i=1;i<=n;i++){
        //se a frequência de i for 0, ele não foi usado
        //para adicionar em um vector, basta dar push_back(x), onde x é o elemento a ser adicionado
        if(freq[i] == 0) not_used.push_back(i);
    }
    for(int i=1;i<=n;i++){
        //se não tiver mas nenhum número não sendo usado, a permutação está feita
        if(not_used.size() == 0) break;
        //se a frequência daquele número for maior que 1, precisamos trocá-lo, ou também se o número do a[i] for maior que n
        if(freq[i] > 1 or a[i] > n){
            //atribui àquele número repetido, o valor de um não usado
            a[i] = not_used.back();
            //remove o não usado da lista
            not_used.pop_back();
            //diminui a frequência do número que acabamos de trocar
            freq[a[i]]--;
        }
    }
    //saída
    for(int i=1;i<=n;i++) cout << a[i] << " ";
    cout << "\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fll fill_n
#define ll long long
#define pb push_back
ll fpb(ll a, ll b){
   if(b==0) return a;
   else return fpb(b,a%b);
}
ll pw(ll a, ll b){
   if(b==0) return 1;
   else{
		ll smp=pw(a,b/2);
		if(b%2==0) return smp*smp;
		else return smp*smp*a;
   }
}

int main(){
	int n;
	cin>>n;
	int frq[100005], ar[100005];
	fll(frq,100005,0);
	for(int i=0; i<n; i++){
		cin>>ar[i];
		frq[ar[i]]++;
	}
	int p=1;
	for(int i=0; i<n; i++){
		if(frq[ar[i]]>1 || ar[i]>n){
			while(frq[p]>0) p++;
			frq[p]++;
			frq[ar[i]]--;
			ar[i]=p++;
		}
	}
	for(int i=0; i<n; i++){
		if(i==n-1) cout<<ar[i]<<endl;
		else cout<<ar[i]<<' ';
	}
}


#include<bits/stdc++.h>
using namespace std;
#define fll fill_n
#define ll long long
#define pb push_back
ll fpb(ll a, ll b){
   if(b==0) return a;
   else return fpb(b,a%b);
}
ll pw(ll a, ll b){
   if(b==0) return 1;
   else{
		ll smp=pw(a,b/2);
		if(b%2==0) return smp*smp;
		else return smp*smp*a;
   }
}

int main(){
	int n;
	cin>>n;
	int frq[100005], ar[100005];
	fll(frq,100005,0);
	for(int i=0; i<n; i++){
		cin>>ar[i];
		frq[ar[i]]++;
	}
	int p=1;
	for(int i=0; i<ar[i]; i++){
		if(frq[ar[i]]>1 || ar[i]>n){
			while(frq[p]>0) p++;
			frq[p]++;
			frq[ar[i]]--;
			ar[i]=p++;
		}
	}
	for(int i=0; i<n; i++){
		if(i==n-1) cout<<ar[i]<<endl;
		else cout<<ar[i]<<' ';
	}
}


#include<bits/stdc++.h>
using namespace std;
#define fll fill_n
#define ll long long
#define pb push_back
ll fpb(ll a, ll b){
   if(b==0) return a;
   else return fpb(b,a%b);
}
ll pw(ll a, ll b){
   if(b==0) return 1;
   else{
		ll smp=pw(a,b/2);
		if(b%2==0) return smp*smp;
		else return smp*smp*a;
   }
}

int main(){
	int n;
	cin>>n;
	int frq[n+5], ar[n+5];
	fll(frq,n+1,0);
	for(int i=0; i<n; i++){
		cin>>ar[i];
		frq[ar[i]]++;
	}
	int p=1;
	for(int i=0; i<ar[i]; i++){
		if(frq[ar[i]]>1 || ar[i]>n){
			while(frq[p]>0) p++;
			frq[p]++;
			frq[ar[i]]--;
			ar[i]=p++;
		}
	}
	for(int i=0; i<n; i++){
		if(i==n-1) cout<<ar[i]<<endl;
		else cout<<ar[i]<<' ';
	}
}


#include<bits/stdc++.h>
using namespace std;
#define fll fill_n
#define ll long long
#define pb push_back
ll fpb(ll a, ll b){
   if(b==0) return a;
   else return fpb(b,a%b);
}
ll pw(ll a, ll b){
   if(b==0) return 1;
   else{
		ll smp=pw(a,b/2);
		if(b%2==0) return smp*smp;
		else return smp*smp*a;
   }
}

int main(){
	int n;
	cin>>n;
	int frq[100005], ar[100005];
	fll(frq,n+1,0);
	for(int i=0; i<n; i++){
		cin>>ar[i];
		frq[ar[i]]++;
	}
	int p=1;
	for(int i=0; i<ar[i]; i++){
		if(frq[ar[i]]>1 || ar[i]>n){
			while(frq[p]>0) p++;
			frq[p]++;
			frq[ar[i]]--;
			ar[i]=p++;
		}
	}
	for(int i=0; i<n; i++){
		if(i==n-1) cout<<ar[i]<<endl;
		else cout<<ar[i]<<' ';
	}
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
#define int long long
#define ll long long
#define vi vector<int>
#define vip vector<pii>
#define mod1 998244353
#define mod 1000000007
#define endl "\n"
#define loop(i,a,b) for(int i=a;i<b;i++)
#define bloop(i,a,b) for(int i=a;i>=b;i--)
#define testcase  int t; cin>>t; while(t--)
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);

using namespace std;

int max(int a, int b) { return (a > b)? a : b; }

int min(int a, int b) { return (a < b)? a : b; }

/*************************************************************************/

int32_t main() {

	FIO
	// testcase
	{
		int n;
		cin>>n;
		vi a(n);
		set<int> s;
		vector<int> hash(1e5+50,0);
		loop(i,0,n)
		{
			cin>>a[i];
			if(a[i]<=n)
				hash[a[i]]++;
			if(a[i]<=n)
				s.insert(a[i]);
		}
		if(n==1)
		{
			cout<<1<<endl;
			return 0;
		}
		if(s.size()==n)
		{
			loop(i,0,n)
				cout<<a[i]<<" ";
			return 0;
		}

		else
		{
			vi v;
			for(int i=1;i<=n;i++)
			{
				if(hash[i]==0)
				v.pb(i);
			}
			int j=0;
			for(int i=0;i<n;i++)
			{
				if(a[i]>n)
				{
					cout<<v[j]<<" ";j++;
				}
				else
				{
					if(hash[a[i]]>=1)
					{
						cout<<a[i]<<" ";
						// j=0;
						hash[a[i]]--;
						while(hash[a[i]]>=1)
						{
							cout<<v[j]<<" ";
							hash[a[i]]--;
							j++;
						}
					}
				}
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
#define int long long
#define ll long long
#define vi vector<int>
#define vip vector<pii>
#define mod1 998244353
#define mod 1000000007
#define endl "\n"
#define loop(i,a,b) for(int i=a;i<b;i++)
#define bloop(i,a,b) for(int i=a;i>=b;i--)
#define testcase  int t; cin>>t; while(t--)
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);

using namespace std;

int max(int a, int b) { return (a > b)? a : b; }

int min(int a, int b) { return (a < b)? a : b; }

/*************************************************************************/

int32_t main() {

	FIO
	// testcase
	{
		int n;
		cin>>n;
		vi a(n);
		set<int> s;
		loop(i,0,n)
		{
			cin>>a[i];
			if(a[i]<=n)
				s.insert(a[i]);
		}
		if(s.size()==n)
		{
			loop(i,0,n)
				cout<<a[i]<<" ";
		}
		else
		{
			for(int i=1;i<=n;i++)
			cout<<i<<" ";
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
#define int long long
#define ll long long
#define vi vector<int>
#define vip vector<pii>
#define mod1 998244353
#define mod 1000000007
#define endl "\n"
#define loop(i,a,b) for(int i=a;i<b;i++)
#define bloop(i,a,b) for(int i=a;i>=b;i--)
#define testcase  int t; cin>>t; while(t--)
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);

using namespace std;

int max(int a, int b) { return (a > b)? a : b; }

int min(int a, int b) { return (a < b)? a : b; }

/*************************************************************************/

int32_t main() {

	FIO
	// testcase
	{
		int n;
		cin>>n;
		vi a(n);
		set<int> s;
		vector<int> hash(n+1,0);
		loop(i,0,n)
		{
			cin>>a[i];
			hash[a[i]]++;
			if(a[i]<=n)
				s.insert(a[i]);
		}
		if(n==1)
		{
			cout<<1<<endl;
			return 0;
		}
		if(s.size()==n)
		{
			loop(i,0,n)
				cout<<a[i]<<" ";
			return 0;
		}

		else
		{
			vi v;
			for(int i=1;i<=n;i++)
			{
				if(hash[i]==0)
				v.pb(i);
			}
			int j=0;
			for(int i=0;i<n;i++)
			{
				if(hash[a[i]]>=1)
				{
					cout<<a[i]<<" ";
					// j=0;
					hash[a[i]]--;
					while(hash[a[i]]>=1)
					{
						cout<<v[j]<<" ";
						hash[a[i]]--;
						j++;
					}
				}
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
#define int long long
#define ll long long
#define vi vector<int>
#define vip vector<pii>
#define mod1 998244353
#define mod 1000000007
#define endl "\n"
#define loop(i,a,b) for(int i=a;i<b;i++)
#define bloop(i,a,b) for(int i=a;i>=b;i--)
#define testcase  int t; cin>>t; while(t--)
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);

using namespace std;

int max(int a, int b) { return (a > b)? a : b; }

int min(int a, int b) { return (a < b)? a : b; }

/*************************************************************************/

int32_t main() {

	FIO
	// testcase
	{
		int n;
		cin>>n;
		vi a(n);
		set<int> s;
		vector<int> hash(1e5+50,0);
		loop(i,0,n)
		{
			cin>>a[i];
			hash[a[i]]++;
			if(a[i]<=n)
				s.insert(a[i]);
		}
		if(n==1)
		{
			cout<<1<<endl;
			return 0;
		}
		if(s.size()==n)
		{
			loop(i,0,n)
				cout<<a[i]<<" ";
			return 0;
		}

		else
		{
			vi v;
			for(int i=1;i<=n;i++)
			{
				if(hash[i]==0)
				v.pb(i);
			}
			int j=0;
			for(int i=0;i<n;i++)
			{
				if(hash[a[i]]>=1)
				{
					cout<<a[i]<<" ";
					// j=0;
					hash[a[i]]--;
					while(hash[a[i]]>=1)
					{
						cout<<v[j]<<" ";
						hash[a[i]]--;
						j++;
					}
				}
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
#define int long long
#define ll long long
#define vi vector<int>
#define vip vector<pii>
#define mod1 998244353
#define mod 1000000007
#define endl "\n"
#define loop(i,a,b) for(int i=a;i<b;i++)
#define bloop(i,a,b) for(int i=a;i>=b;i--)
#define testcase  int t; cin>>t; while(t--)
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);

using namespace std;

int max(int a, int b) { return (a > b)? a : b; }

int min(int a, int b) { return (a < b)? a : b; }

/*************************************************************************/

int32_t main() {

	FIO
	// testcase
	{
		int n;
		cin>>n;
		vi a(n);
		set<int> s;
		vector<int> hash(n+1,0);
		loop(i,0,n)
		{
			cin>>a[i];
			hash[a[i]]++;
			if(a[i]<=n)
				s.insert(a[i]);
		}
		if(s.size()==n)
		{
			loop(i,0,n)
				cout<<a[i]<<" ";
			return 0;
		}
		if(n==1)
		{
			cout<<1<<endl;
			return 0;
		}
		else
		{
			vi v;
			for(int i=1;i<=n;i++)
			{
				if(hash[i]==0)
				v.pb(i);
			}
			int j=0;
			for(int i=0;i<n;i++)
			{
				if(hash[a[i]]>=1)
				{
					cout<<a[i]<<" ";
					// j=0;
					hash[a[i]]--;
					while(hash[a[i]]>=1)
					{
						cout<<v[j]<<" ";
						hash[a[i]]--;
						j++;
					}
				}
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
#define int long long
#define ll long long
#define vi vector<int>
#define vip vector<pii>
#define mod1 998244353
#define mod 1000000007
#define endl "\n"
#define loop(i,a,b) for(int i=a;i<b;i++)
#define bloop(i,a,b) for(int i=a;i>=b;i--)
#define testcase  int t; cin>>t; while(t--)
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);

using namespace std;

int max(int a, int b) { return (a > b)? a : b; }

int min(int a, int b) { return (a < b)? a : b; }

/*************************************************************************/

int32_t main() {

	FIO
	// testcase
	{
		int n;
		cin>>n;
		vi a(n);
		set<int> s;
		vector<int> hash(n+1,0);
		loop(i,0,n)
		{
			cin>>a[i];
			hash[a[i]]++;
			if(a[i]<=n)
				s.insert(a[i]);
		}
		if(s.size()==n)
		{
			loop(i,0,n)
				cout<<a[i]<<" ";
		}
		else
		{
			vi v;
			for(int i=1;i<=n;i++)
			{
				if(hash[i]==0)
				v.pb(i);
			}
			int j=0;
			for(int i=0;i<n;i++)
			{
				if(hash[a[i]]>=1)
				{
					cout<<a[i]<<" ";
					// j=0;
					hash[a[i]]--;
					while(hash[a[i]]>=1)
					{
						cout<<v[j]<<" ";
						hash[a[i]]--;
						j++;
					}
				}
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
#define int long long
#define ll long long
#define vi vector<int>
#define vip vector<pii>
#define mod1 998244353
#define mod 1000000007
#define endl "\n"
#define loop(i,a,b) for(int i=a;i<b;i++)
#define bloop(i,a,b) for(int i=a;i>=b;i--)
#define testcase  int t; cin>>t; while(t--)
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);

using namespace std;

int max(int a, int b) { return (a > b)? a : b; }

int min(int a, int b) { return (a < b)? a : b; }

/*************************************************************************/

int32_t main() {

	FIO
	// testcase
	{
		int n;
		cin>>n;
		vi a(n);
		set<int> s;
		vector<int> hash(1e5+50,0);
		loop(i,0,n)
		{
			cin>>a[i];
			if(a[i]<=n)
				hash[a[i]]++;
			if(a[i]<=n)
				s.insert(a[i]);
		}
		if(n==1)
		{
			cout<<1<<endl;
			return 0;
		}
		if(s.size()==n)
		{
			loop(i,0,n)
				cout<<a[i]<<" ";
			return 0;
		}

		else
		{
			vi v;
			for(int i=1;i<=n;i++)
			{
				if(hash[i]==0)
				v.pb(i);
			}
			int j=0;
			for(int i=0;i<n;i++)
			{
				if(a[i]>n)
				{
					cout<<v[j]<<" ";j++;
				}
				else
				{
					if(hash[a[i]]==1)
					{
						cout<<a[i]<<" ";
					}
					else if(hash[a[i]]>1)
					{
						cout<<a[i]<<" ";
						hash[a[i]]=-1;
					}
					else if(hash[a[i]]==-1)
					{
						cout<<v[j]<<" ";
						j++;
					}
				}
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int arr[100010];
int mk[100010];
int Mp[100010];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&arr[i]);
        mk[arr[i]] = 1;
    }
    vector<int>V,res;
    for(int i=1; i<=n; i++)
    {
        if(mk[i]==0)V.push_back(i);
    }
    memset(mk,0,sizeof(mk));

    for(int i=1; i<=n; i++)
    {
        if(mk[arr[i]])
        {
            res.push_back(V[V.size()-1]);
            V.pop_back();
        }
        else res.push_back(arr[i]);
        mk[arr[i]] = 1;
    }
    memset(mk,0,sizeof(mk));
    V.clear();
    for(int i=0;i<n; i++)
    {
        if(1<= res[i] && res[i]<=n) mk[res[i]] = 1;
    }
    for(int i=1; i<=n; i++)
    {
        if(mk[i]==0) V.push_back(i);
    }
    for(int i=0;i<res.size();i++)
    {
        if(mk[res[i]]) cout << res[i] << " ";
        else
        {
            cout << V[V.size()-1] << " ";
            V.pop_back();
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int arr[1000100];
int mk[1000100];
    int Mp[1000100];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%lld",&arr[i]);
        mk[arr[i]] = 1;
    }
    vector<int>V,res;
    for(int i=1; i<=n; i++)
    {
        if(mk[i]==0)V.push_back(i);
    }
    memset(mk,0,sizeof(mk));

    for(int i=1; i<=n; i++)
    {
        if(mk[arr[i]])
        {
            res.push_back(V[V.size()-1]);
            V.pop_back();
        }
        else res.push_back(arr[i]);
        mk[arr[i]] = 1;
    }
    vector<int>cpy;
    cpy = res;
    sort(cpy.begin(),cpy.end());
    for(int i=0; i<cpy.size(); i++)
    {
        Mp[cpy[i]] = i+1;
    }
    for(int i=0;i<n;i++)
    {
        int val = Mp[res[i]];
        cout << val << " ";
    }
}


#include<bits/stdc++.h>
using namespace std;
int arr[1000100];
int mk[1000100];
    int Mp[1000100];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&arr[i]);
        mk[arr[i]] = 1;
    }
    vector<int>V,res;
    for(int i=1; i<=n; i++)
    {
        if(mk[i]==0)V.push_back(i);
    }
    memset(mk,0,sizeof(mk));

    for(int i=1; i<=n; i++)
    {
        if(mk[arr[i]])
        {
            res.push_back(V[V.size()-1]);
            V.pop_back();
        }
        else res.push_back(arr[i]);
        mk[arr[i]] = 1;
    }
    vector<int>cpy;
    cpy = res;
    sort(cpy.begin(),cpy.end());
    for(int i=0; i<cpy.size(); i++)
    {
        Mp[cpy[i]] = i+1;
    }
    for(int i=0;i<res.size();i++)
    {
        int val = Mp[res[i]];
        cout << val << " ";
    }
}


// Author : Dhiraj Gandhi.
// Institute : PICT,Pune.

#include<bits/stdc++.h>
using namespace std;
#define int long long int
struct abc{int pos,val;};
bool compare(abc x1,abc x2){return (x1.pos<x2.pos);}
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int lcm(int a,int b){return (a*b)/gcd(a,b);}

const int N=2e5+3,A=1e6+3;
int n,k;
string b[1000001],s;
int32_t main()
{
	cin>>n;
	int a[n+1]={0},b[n+1]={0},j=1,x;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(b[x]==0 && x<=n)
		{
		b[x]++;
		a[i]=x;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(b[i]==0)
		{
			while(a[j]!=0)
			j++;
			a[j]=i;
		}
	}
	for(int i=1;i<=n;i++)cout<<a[i]<<' ';
}


// Author : Dhiraj Gandhi.
// Institute : PICT,Pune.

#include<bits/stdc++.h>
using namespace std;
#define int long long int
struct abc{int pos,val;};
bool compare(abc x1,abc x2){return (x1.pos<x2.pos);}
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int lcm(int a,int b){return (a*b)/gcd(a,b);}

const int N=2e5+3,A=1e6+3;
int n,k;
string s;
int a[100005],b[100005];
int32_t main()
{
	cin>>n;
	int j=1,x;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(b[x]==0 && x<=n)
		{
		b[x]++;
		a[i]=x;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(b[i]==0)
		{
			while(a[j]!=0)
			j++;
			a[j]=i;
		}
	}
	for(int i=1;i<=n;i++)cout<<a[i]<<' ';
}


// Author : Dhiraj Gandhi.
// Institute : PICT,Pune.

#include<bits/stdc++.h>
using namespace std;
#define int long long int
struct abc{int pos,val;};
bool compare(abc x1,abc x2){return (x1.pos<x2.pos);}
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int lcm(int a,int b){return (a*b)/gcd(a,b);}

const int N=2e5+3,A=1e6+3;
int n,k;
string b[1000001],s;
int32_t main()
{
	cin>>n;
	int a[n+1]={0},b[n+1]={0},j=1,x;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(a[x]==0 && x<=n)
		{
			a[x]++;
			cout<<x<<' ';
		}
		else
		{
			while(a[j]!=0)j++;
			cout<<j<<' ';
			a[j]=1;
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    int a[n+1]={0};
    set <int> ms, vs;
    for(int i=1; i<=n; i++)
    {
        int x;
        cin >> x;
        if(ms.find(x)==ms.end() && x<=n)
            {
                a[i]=x;
                ms.insert(x);
            }
    }
    for(int i=1; i<=n; i++)
    {
        if(ms.find(i)==ms.end())
        {
            vs.insert(i);
            ms.insert(i);
        }
    }
    for(int i=1; i<=n; i++)
    {
        if(a[i])
            cout << a[i] << " ";
        else
        {
            auto it=vs.begin();
            cout << *it << " ";
            vs.erase(it);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++)
    {
        cin >> a[i];
    }
    vector <int> v;
    unordered_set <int> ms;
    int cnt=1;
    for(int i=0; i<n; i++)
    {
        if(ms.find(a[i])==ms.end() && a[i]<=n)
        {
            v.push_back(a[i]);
            ms.insert(a[i]);
        }
        else
        {
            while(ms.find(cnt)!=ms.end())
                cnt++;
            ms.insert(cnt);
            v.push_back(cnt++);
        }
    }
    for(auto i:v)
        cout << i << " ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++)
    {
        cin >> a[i];
    }
    vector <int> v;
    unordered_set <int> ms;
    for(int i=0; i<n; i++)
    {
        if(ms.find(a[i])==ms.end())
        {
            if(a[i]>n)
            {
                int cnt=n;
                while(ms.find(cnt)!=ms.end() && cnt)
                    cnt--;
                v.push_back(cnt);
                continue;
            }
            v.push_back(a[i]);
            ms.insert(a[i]);
        }
        else
        {
            int cnt=a[i];
            while(ms.find(cnt)!=ms.end() && cnt)
                cnt--;
            if(!cnt)
            {
                cnt=a[i];
                while(ms.find(cnt)!=ms.end() && cnt<=n)
                    cnt++;
            }
            ms.insert(cnt);
            v.push_back(cnt);
        }
    }
    for(auto i:v)
        cout << i << " ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rep2(r, aa, bb) for (int r = (aa)-1; r >= (bb); r--)
#define be(x) (x.begin(), x.end())
#define pb(t) push_back(t)
#define ll long long
#define mp(a, b) make_pair(a, b)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    vector<pair<int,int>>A(n);
    vector<int>ans(n, 0);
    set<int>isthere;
    rep(i,1,n+1)isthere.insert(i);
    rep(i,0,n){cin>>A[i].first; A[i].second=i;}
    sort be(A);
    rep(i,0,n)
    {
        if(A[i].first>n)break;
        if(!isthere.count(A[i].first))continue;
        //cout<<A[i].first<<" d "<<A[i].second<<"\n";
        ans[A[i].second]=A[i].first;
        isthere.erase(A[i].first);
    }
    rep(i,0,n)
    {
        if(ans[A[i].second]==0)
        ans[A[i].second]=*isthere.begin(), isthere.erase(*isthere.begin());
    }
    for(int i:ans)cout<<i<<" ";
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rep2(r, aa, bb) for (int r = (aa)-1; r >= (bb); r--)
#define be(x) (x.begin(), x.end())
#define pb(t) push_back(t)
#define ll long long
#define mp(a, b) make_pair(a, b)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    vector<pair<int,int>>A(n);
    vector<int>ans(n, 0);
    set<int>isthere;
    rep(i,1,n+1)isthere.insert(i);
    rep(i,0,n){cin>>A[i].first; A[i].second=i;}
    sort be(A);
    rep(i,0,n)
    {
        if(A[i].first>n)break;
        if(isthere.count(A[i].first))continue;
        ans[A[i].second]=A[i].first;
        isthere.erase(A[i].first);
    }
    rep(i,0,n)
    {
        if(ans[A[i].second]==0)
        ans[A[i].second]=*isthere.begin(), isthere.erase(*isthere.begin());
    }
    for(int i:ans)cout<<i<<" ";
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rep2(r, aa, bb) for (int r = (aa)-1; r >= (bb); r--)
#define be(x) (x.begin(), x.end())
#define pb(t) push_back(t)
#define ll long long
#define mp(a, b) make_pair(a, b)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    vector<pair<int,int>>A(n);
    vector<int>ans(n, 0);
    set<int>isthere;
    rep(i,1,n+1)isthere.insert(i);
    rep(i,0,n){cin>>A[i].first; A[i].second=i;}
    sort be(A);
    rep(i,0,n)
    {
        if(A[i].first>n)break;
        if(!isthere.count(A[i].first))continue;
        //cout<<A[i].first<<" d "<<A[i].second<<"\n";
        ans[A[i].second]=A[i].first;
        isthere.erase(A[i].first);
    }
    rep(i,0,n)
    {
        if(ans[A[i].second]==0)
        ans[A[i].second]=*isthere.begin(), isthere.erase(*isthere.begin()), cout<<A[i].first<<"\n";
    }
    for(int i:ans)cout<<i<<" ";
}


#include<iostream>
#include<algorithm>
int a[105];
using namespace std;
int main(){
    int n,m,j=0,sum=0;
    cin>>n>>m;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    while(m--&&a[j]>0){
        sum+=a[j];
        j++;
    }
    cout<<-sum<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool compare(int a,int b){
return a>b; }
int main(){
    int n,m;
    cin>>n>>m;
    int a[100];
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]=0-a[i];}

    sort(a+1,a+n+1,compare);
    int sum=0;
    for(int i=0;i<m;i++){
        if(a[i]>0)
            sum+=a[i];
    }
    cout<<sum<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long LiChuhan;
LiChuhan likes,a[101],pretty,girl;
int cmd(int very,int much)
{
	return very<much;
}
int main()
{
	cin>>likes>>pretty;
	for(int i=1;i<=likes;i++)
		cin>>a[i];
	sort(a+1,a+likes+1,cmd);
	/*for(int i=1;i<=likes;i++)
		cout<<a[i]<<" ";*/
	for(int i=1;i<=pretty;i++)
	    if(a[i]<0)
	       girl+=a[i];
	cout<<girl*(-1)<<endl;
	return 0;
}


#include<cstdio>
#include<cmath>
#include<algorithm>
int main() {
    int n,m,a[105],ans=0;
	scanf("%d%d",&n,&m);

	for(int i=1; i<=n; i++)
		scanf("%d", &a[i]);

	std::sort(a+1, a+n+1);

	for(int i=1; i<=m; i++)
		if(a[i]<0)
			ans+=abs(a[i]);

	printf("%d", ans);
}


#include<bits/stdc++.h>
using namespace std;
int i,j,n,a[110],m;
int main()
{
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(i=1;i<=m;i++)
		j-=a[i];
	printf("%d",j);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#define N 1000000
#define LL long long
using namespace std;
LL a[N],n,m,sum=0;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		a[i]=0-a[i];
	}
	sort(a,a+n);
	for(int i=n-1;i>=n-m;i--)
	{
		if(a[i]>0)
		sum+=a[i];
        else
		break;
	}
	cout<<sum;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int N,M;
int a[10200];
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	cin>>N>>M;
	for(int i=1;i<=N;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+N+1,cmp);
	int maxn=0;
	for(int i=1;i<=M;i++)
	{
		maxn+=a[i];
	}
	cout<<maxn;
	return 0;
}


#include<cstdio>
#include<cmath>
#include<algorithm>
int main() {
    int n,m,a[105],ans=0;
	scanf("%d%d",&n,&m);

	for(int i=1; i<=n; i++)
		scanf("%d", &a[i]);

	std::sort(arr+1, arr+n+1);

	for(int i=1; i<=m; i++)
		if(a[i]<0)
			ans+=abs(a[i]);

	printf("%d", ans);
}


#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
	long n,i;
	cin>>n>>i;
	long p[n];
	for (int j=0; j<n; j++)
		cin>>p[j];
	sort(p, p+n);
	int sum=0;
	for (int j=0; j<i; j++)
		sum+=p[j];
	cout<<abs(sum);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,k,sum,i,a[110];
int main(){
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(i=1;i<=k;i++) sum-=a[i];
	printf("%d",sum);
}


#include<iostream>
#include<algorithm>
using namespace std;
int n,m,a[1005];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+1+n);
	int cnt=0;
	for(int i=1;i<=m;i++){
		if(a[i]>0) break;
		cnt-=a[i];
	}
	cout<<cnt;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m,a[110000];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	int ans=0;
	for(int i=1;i<=m;i++)
	{
		ans-=a[i];
	}
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
int i,j,n,a[110],m;
int main()
{
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(i=1;i<=m;i++)
	{
		if(a[i]<=0)
			j-=a[i];
		else
			break;
	}
	printf("%d",j);
	return 0;
}


# include <iostream>
# include <algorithm>
using namespace std;

int main()
{
	int n, i, ai[i], m, sum = 0;
	cin >> n >> m;
	for(i = 0;i < n;i++){
		cin >> ai[i];
	}
	sort(ai,ai+n);//排序
	for(i = 0;i < n;i++){
		if(ai[i] < 0){
			sum -= ai[i];
			m--;
		}
		if(m == 0|| ai[i] >= 0) break;
	}
	cout << sum;
}


#include <bits/stdc++.h>
using namespace std;
int n,m,a[110],money;
int main () {
	cin>>n>>m;
	for (int i=1;i<=n;i++) {
		int x;
		cin>>x;
		a[i]=0-x;
	}
	sort(a+1,a+n+1);
	for (int i=n;i>=n-m+1;i--)
		if(a[i]>0) money+=a[i];
		else break;
	printf ("%d\n",money);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int arr[110];
long long ans;
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    sort(arr+1,arr+1+n);
    for(int i=1;i<=m;i++)
    {
        ans-=arr[i];
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[110];
int main() {
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	scanf("%d",&a[i]);
	sort(a,a+n);
	int s=0;
	for(int i=0;i<m;i++)
	s+=a[i];
	printf("%d",abs(s));
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int a[110];
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+n+1);
    int sum=0;
    for(int i=1;i<=m;i++) sum+=a[i];
    cout<<-sum;
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')s=s*10+(ch-'0'),ch=getchar();
	return s*w;
}
const int MAXN=110;
int n,m,a[MAXN],ans;
void dfs(int x,int tmp,int sum)
{
	if(x>n)
	{
		ans=max(ans,sum);
		return;
	}
	dfs(x+1,tmp,sum);
	if(tmp+1<=m) dfs(x+1,tmp+1,sum+a[x]);
}
int main()
{
	n=read(),m=read();
	for(register int i=1;i<=n;i++) a[i]=-read();
	dfs(1,0,0);
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m;
const int maxn=200;
int a[maxn];
int ans;
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	int now=0;
	for(int i=0;i<n;i++)
	{
		if(now<m)
		{
			ans+=abs(a[i]);now++;
		}
		else break;

	}
	cout<<ans<<endl;
}


#include<iostream>
#include<cmath>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m;
int v[101];
int ans;
bool cmp(int x,int y)
{
	return x<y;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>v[i];
	}
	sort(v+1,v+n+1);
	for(int i=1;i<=m;i++)
	{
		ans-=v[i];
	}
	cout<<ans;
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,num,a[101],sum=0;
	cin>>n>>num;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<=num;i++)
		sum+=a[i];
	cout<<0-sum;
	return 0;
}


#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

int num[1001];
int n, m, ans;

int main()
{
	scanf("%d%d",&n, &m);
	for(int i = 1;i <= n; i++)
		scanf("%d",&num[i]);
	sort(num + 1,num + n + 1);
	for(int i = 1;i <= m; i++)
		if(num[i] < 0)
			ans += (-num[i]);
	printf("%d",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
    int n, m, res = 0;
    scanf("%d%d", &n, &m);
    int* a = new int[n];
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);
    sort(a, a + n);
    for(int i = 0; i < m && a[i] <= 0; i++) res += a[i];
    res = (-1) * res;
    printf("%d", res);
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,ans=0;
	cin>>n>>m;
	int a[100005];
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=m;i++){
		ans+=a[i];
	}
	cout<<ans<<endl;
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,x,a[200],money;
int main()
{
  scanf("%d%d",&n,&m);
 for(int i=1;i<=n;i++)
  scanf("%d",&x),a[i]=0-x;
 sort(a+1,a+n+1);
 for(int i=n;i>=n-m+1;i--)
 {
  if(a[i]>0)  money+=a[i];
  else  break;
 }
 printf("%d",money);
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m,a[101],money=0;
int main()
{
 cin>>n>>m;
 for(int i=1;i<=n;i++)
 {
  int x;
  cin>>x;
  a[i]=0-x;
 }
 sort(a+1,a+n+1);
 for(int i=n;i>=n-m+1;i--)
 {
  if(a[i]>0) money+=a[i];
        else break;
 }
 cout<<money;
}


#include<bits/stdc++.h>
using namespace std;
int a[1000001];
int main(){
	int m,n;
	cin>>m>>n;
	for(int i=1;i<=m;i++)
	cin>>a[i];
	sort(a+1,a+m+1);
	int sum=0;
	for(int i=1;i<=n;i++)
	sum+=a[i];
	cout<<-1*sum;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int s=0,n,m,i,a[101];
	cin>>n>>m;
	for(i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	for(i=1;i<=m;i++) if(a[i]<0) s=s+a[i];
	cout<<-s;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[10000],n,sum;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]<0) sum=sum-a[i];
	}
	cout<<sum;
}


#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int n, m, ans = 0, cnt = 0;
    cin >> n >> m;
    const int f = n;
    int arr[f];
    for(int i = 0; i <= f - 1; i++)
    {
        cin >> arr[i];
    }
    sort(arr, arr + f);
    for(int i = 0; i <= f - 1; i++)
    {
        if(arr[i] < 0)
        {
            ans += abs(arr[i]);
            cnt++;
        }
        if(cnt >= m)
        {
            cout << ans << endl;
            return 0;
        }
    }
    sort(arr, arr + f);
    for(int i = 0; i <= f - 1; i++)
    {
        if(arr[i] >= 0)
        {
            ans -= arr[i];
            cnt++;
        }
        if(cnt >= m)
        {
            cout << ans << endl;
            return 0;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m,a[101],sum=0;
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	for(int i=0;i<m;i++){
		if(a[i]<=0) sum+=a[i];
	}
	cout<<0-sum<<endl;
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
	int n,m,a[105];
	cin >> n >> m;
	for (int i=0;i<n;i++)
	{
		cin >> a[i];
	}
	sort(a,a+n);
//	for (int i=0;i<n;i++)
//	cout << a[i] << " ";

	int ans=0;
	for (int i=0;i<m;i++)
	{
		ans+=a[i];
//		cout << ans << " ";
	}
	if(ans>0)
	cout << ans;
	else
	cout << abs(ans);

	return 0;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <stack>
#include <cctype>
#include <map>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	vector<int> arrPrice;
	int nTVs,nBuy,i,iSum,iTmp;
	cin>>nTVs>>nBuy;
	for (i=1;i<=nTVs;++i){
	    cin>>iTmp;
	    arrPrice.push_back(iTmp);
	}
	sort(begin(arrPrice),end(arrPrice));
	for (i=0;i<=nTVs-1;++i){
	    if (i>=nBuy){
	        break;
	    }
	    if (arrPrice[i]>=0){
	        break;
	    }
	    iSum+=arrPrice[i];
	}
	cout<<(-iSum);
    endapp:
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[199];
int main()
{
	int n,m;
	cin>>n>>m;
	int temp=0;
	for(int i=1;i<=n;i++)
	{
	cin>>temp;
	a[i]=-temp;
    }
	sort(a+1,a+n+1);
	temp=0;
    for(int i=n;i>=n-m+1;i--)
    {
     if(a[i]>0) temp+=a[i];
         else break;
    }
    cout<<temp<<endl;
}


#include<bits/stdc++.h>
using namespace std;
bool cmp(int x,int y)
{
	return x<y;
}
int a[101];
int main()
{
	int n,m,sum=0;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=m;i++)
	sum-=a[i];
	cout<<sum;
}


#include<stdio.h>
#include <queue>

using namespace std;

int main()
{
	priority_queue<long long,vector<long long>, greater<long long> > a;

	int n;
	scanf("%d",&n);
	long long m;
	scanf("%lld",&m);

	long long vv;
	while(n--)
	{
		scanf("%lld",&vv);
		a.push(vv);
	}

	long long count=0;

	while(m>0&&a.top()<=0)
	{
		count=count-a.top();

		m--;
		a.pop();
	}
	printf("%lld",count);
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int a[100];
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]=0-a[i];}
    sort(a+1,a+n+1);
    int sum=0;
    for(int i=0;i<m;i++){
        sum+=a[i];
    }
    cout<<sum<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m,sum;
int a[10001];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=m;i++)
	{
		if(a[i]>0)
		sum+=-(a[i]);
		else
		sum+=abs(a[i]);
	}
	printf("%d",sum);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,a[1005],m,sum;
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<=m;i++)
	sum+=a[i];
	cout<<sum*-1;

 return 0;
}


# include <bits/stdc++.h>
using namespace std;

typedef long long ll;
ll m, n, a[105], ans;

inline ll read () {
	ll x=0, y=1; char ch='\000';
	for (; !isdigit (ch); ch=getchar ()) if (ch=='-') y=-1;
	for (; isdigit (ch); ch=getchar ()) x=(x<<3)+(x<<1)+(ch^'0');
	return x*y;
}

inline void _merge (ll a[], ll l, ll r) {
	ll mid=(l+r)>>1, u[105]={0};
	ll x0=l, x1=mid+1, x2=0;

	while (x0<=mid && x1<=r)
		if (a[x0]<a[x1]) u[++x2]=a[x0++];
		else u[++x2]=a[x1++];
	while (x0<=mid) u[++x2]=a[x0++];
	while (x1<=r) u[++x2]=a[x1++];

	for (ll i=l; i<=r; i++) a[i]=u[i-l+1];
	return;
}

inline void _merge_sort (ll a[], ll l, ll r) {
	if (l>=r) return;
	ll mid=(l+r)>>1;
	_merge_sort (a, l, mid);
	_merge_sort (a, mid+1, r);
	_merge (a, l, r);
	return;
}

int main () {

	n=read (); m=read ();
	for (ll i=1; i<=n; i++) a[i]=read ();

	_merge_sort (a, 1, n);
	for (ll i=1; i<=m; i++) ans+=a[i];

	printf ("%lld\n", -ans);

	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int a[n+5];
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	int sum=0;
	for(int i=1;i<=m;i++)
	{
		if(a[i]>0)break;
		else sum+=a[i];
	}
	printf("%d",sum*-1);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m,a[101],money=0;
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        a[i]=0-x;
    }
    sort(a+1,a+n+1);
    for(int i=n;i>=n-m+1;i--)
    {
        if(a[i]>0) money+=a[i];
        else break;
    }
    cout<<money;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=1e2+5;
int price[105];
int main(){
	int n,m,ans=0,i;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++){
    	scanf("%d",&price[i]);
	}
    sort(price+1,price+n+1);
    for(i=1;i<=m;i++){
        if(price[i]<0){
        	ans+=price[i];
		}
    }
    printf("%d",ans*-1);
    return 0;
}


# include <iostream>
# include <algorithm>
using namespace std;

int main()
{
	int n, i, ai[102], m, sum = 0;
	cin >> n >> m;
	for(i = 0;i < n;i++){
		cin >> ai[i];
	}
	sort(ai,ai+n);//排序
	for(i = 0;i < m;i++){
	    if(ai[i] < 0)
			sum -= ai[i];
		else break;
	}
	cout << sum;
}


#include<bits/stdc++.h>
using namespace std;
int n,m,a[110000],j=0,b[110000];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]<0)
		{
			j++;
			b[j]=a[i];
		}
	}
	sort(b+1,b+j+1);
	int ans=0;
	for(int i=1;i<=min(m,j);i++)
	{
		ans-=b[i];
	}
	cout<<ans;
}


#include<iostream>
#include<algorithm>
using namespace std;
int m,n,a[101],ans,i;
int main()
{
	cin>>n>>m;
	for (i=1;i<=n;i++)
	  cin>>a[i];
	sort(a+1,a+n+1);
	for (i=1;i<=m;i++)
	  if (a[i]<0) ans-=a[i];
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int n,m,ans,a[1005];
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		a[i]=-a[i];
	}
	sort(a+1,a+n+1,greater<int>());
	for(int i=1;i<=m;i++)
	ans+=a[i];
	cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,i,a[105],ans=0;
	cin>>n>>m;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	for(i=0;i<m;i++)
	{
		if(a[i]<0)
		{
			ans-=a[i];
		}
		else
		{
			break;
		}
	}
	cout<<ans<<endl;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN=100+10;
int a[MAXN],n,m,ans;
int main() {
	cin>>n>>m;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<m;i++) ans+=a[i];
	cout<<-ans;
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,m,a[100],ans=0;
	cin>>n>>m;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++)
	{
		if(m==0) break;
		if(a[i]<=0) ans+=abs(a[i]);
		m--;
		if(a[i+1]>0) break;
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
int n,m,price[105],ans=0;
int main()
{
    cin >> n >> m;
    for(int i=1; i<=n; i++)
        cin >>  price[i];
    sort(price+1,price+n+1);
    for(int i=1; i<=m; i++)
    {
        if(price[i]<0)
            ans+=price[i];
    }
    cout << -1*ans;
    return 0;
}


#include<iostream>
using namespace std;
int n,m,t,ans,sum;
struct ff{
	int num,l,r,cnt;
} a[105];
void maketree(int x,int y){
	if(!a[x].cnt){
	    a[x].cnt=y;
	    ans++;
	    a[x].num++;
	    return ;
	}
	if(y==a[x].cnt) a[x].num++;
	else if( y<a[x].cnt){
	    if(!a[x].l){  ans++;
	       ans++;
	       a[x].l=ans;
	       a[ans].cnt=y;
	       a[ans].num++;
	    }
		else
		maketree(a[x].l,y);
	}
	else if(y<a[x].cnt){
		if(!a[x].r){
			ans++;
			a[x].r=ans;
			a[ans].num++;
			a[ans].cnt=y;
		}
		else
	    maketree(a[x].r,y);
	}
}
int cn;
int find(int x){
	if(a[x].l){
		find(a[x].l);
	}
	if(a[a[x].l].cnt<0 && cn<m){
		cn+=a[a[x].l].num;
		if(cn<=m)
		sum+=(a[a[x].l].num)*a[a[x].l].cnt;
		else
		sum+=(m-cn)*a[a[x].num].cnt;
	}
	if(a[x].r) find(a[x].r);
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		 cin>>t;
		 maketree(1,t);
	}
	find(1);
	cout<<-1*sum;
	return 0;
}


#include<iostream>
using namespace std;
struct Node
{
	int dis,rc,lc,father;
}f[1666];
int n,t,ans,m;
void cmp(int x,int y)
{
	if(x<=f[y].dis)
	{
		if(f[y].lc==0)
		{
			f[y].lc=++t;
			f[t].dis=x;
			return ;
		}
		cmp(x,f[y].lc);
	}
	else if(x>f[y].dis)
	{
		if(f[y].rc==0)
		{
			f[y].rc=++t;
			f[t].dis=x;
			return ;
		}
		cmp(x,f[y].rc);
	}
	return ;
}
void dfs(int x)
{
	if(f[x].lc==0&&f[x].rc==0)return ;
	if(m==0)return ;
	if(f[f[x].lc].dis<=x&&f[x].lc!=0)dfs(f[x].lc);
	ans=max(ans,ans-f[x].dis);
	if(f[f[x].rc].dis<x&&f[x].rc!=0)dfs(f[x].rc);
	return ;
}
int main()
{
	f[0].dis=0;
	cin>>n>>m;
	for(int i=1;i<=n;++i)
	{
		int a;
		cin>>a;
		cmp(a,0);
	}
	dfs(0);
	cout<<ans<<endl;
	return 0;
}
//7 4 -8 -7 -1 -1 -1 5 6


#include <iostream>
#include <algorithm>

using namespace std;

int a[110];

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
	}
	sort(a + 1, a + 1 + n);
	int sum = 0;
	for (int i = 1; i <= m; ++i)
	{
		sum += a[i];
	}
	cout << -sum;
	return 0;
}


#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#define N 1000000
#define LL long long
using namespace std;
LL a[N],n,m,sum=0;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		a[i]=0-a[i];
	}
	sort(a,a+n);
	for(int i=0;i<m;i++)
	sum+=a[i];
	cout<<-sum;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,m,a[100001],ans,i,j;
int  main()
{
	cin>>n>>m;
	for(i=1;i<=n;i++)
	cin>>a[i];
	sort(a+1,a+1+n);
	for(i=1;i<=m;i++)
	{
		if(a[i]<=0)
	{
		a[i]=abs(a[i]);
		ans+=a[i];
		}
	}
	cout<<ans<<endl;
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int m,n,a[101],ans=0,r;
signed main(){
	cin>>m>>n;
	for(int i=1;i<=m;i++){
		cin>>a[i];
	}sort(a+1,a+m+1);
	for(int i=1;i<=n;i++){
		if(a[i]<=0) r=r-a[i];
		else break;
	}
	cout<<r;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long sum=0;
int n,m,a[109];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+1+n);
	for(int i=1;i<=m;i++)
	{
		if(a[i]<=0)
        {
            sum=sum+(0-a[i]);
        }
	}
	cout<<sum;
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int a[100001];
long long sum=0;
int main(){
	int i,j,k,n,m;
	cin>>n>>m;
	for(i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
	for(i=1;i<=m;i++)sum+=a[i];
	cout<<-sum<<endl;
	return 0;
}


#include<stdio.h>
#include<algorithm>
int main() {
	int n,m,a[102];
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	std::sort(a+1,a+1+n);
	int price=0;
	for(int i=1;i<=m;i++) if(a[i]<=0) price-=a[i];
	printf("%d",price);
}


#include<iostream>
#include<fstream>
#include<cstring>
#include<string>
#include<vector>
#include<deque>
#include<sstream>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
using namespace std;
int a[101],n,m,ans;
int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<m;i++){
        ans-=a[i];
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define F first
#define S second
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    vector<ll> A ;
    ll n , x  , m  ;
    cin >> n >> m;
    while(n--){
        cin >> x;
        A.pb(x) ;
    }

    sort(A.begin() , A.end()) ;
    ll dem = 1 , sum = 0 ;
    for (int i = 0 ; i < m ; i++){
        if ( A[i] >= 0)
            break;

        sum+=A[i] ;
    }

    cout << abs(sum) ;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define F first
#define S second
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    vector<ll> A ;
    ll n , x  , m  ;
    cin >> n >> m;
    while(n--){
        cin >> x;
        A.pb(x) ;
    }

    sort(A.begin() , A.end()) ;
    ll dem = 1 , sum = A[0] ;
    for (int i = 1 ; i < A.size() ; i++){
        if ( dem == m ){
            cout << ans ;
            return 0 ;
        }
        sum+=A[i] ;
        dem++;

    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define F first
#define S second
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    vector<ll> A ;
    ll n , x  , m  ;
    cin >> n >> m;
    while(n--){
        cin >> x;
        A.pb(x) ;
    }

    sort(A.begin() , A.end()) ;
    ll dem = 1 , sum = 0 ;
    for (int i = 0 ; i < m ; i++){
        if ( A[i] >= 0)
            break;

        sum+=A[i] ;
    }

    cout << sum ;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define F first
#define S second
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    vector<ll> A ;
    ll n , x  , m  ;
    cin >> n >> m;
    while(n--){
        cin >> x;
        A.pb(x) ;
    }

    sort(A.begin() , A.end()) ;
    ll dem = 1 , sum = A[0] ;
    for (int i = 1 ; i < A.size() ; i++){
        if ( dem == m ){
            if (sum < 0 )
                cout << abs(sum);
            else
                cout << sum ;
            return 0 ;
        }
        sum+=A[i] ;
        dem++;

    }
    return 0;
}


#include<iostream>
#include<cstdio>
#define re register int
using namespace std;
struct tq
{
	int data,left,right,num;
}q[101];
int n,m,cnt,ans[101],money;
void add(int x,int now)//bst插入
{
	//bst左孩子一定小于父亲，右孩子一定大于父亲
	if(q[x].data<q[now].data)//小于父亲，向左子树插入
	{
		if(q[now].left==0)//没左儿子，直接当儿子
			q[now].left=x;
		else	//有左儿子，向左儿子的子树中插入
			add(x,q[now].left);
	}
	else if(q[x].data>q[now].data)//大于父亲，向右子树插入
	{
		if(q[now].right==0)//没右儿子，直接当儿子
			q[now].right=x;
		else	//有右儿子，向右儿子的子树中插入
			add(x,q[now].right);
	}
	else if(x!=1)
		q[now].num++;	//已经有，计数
}
void dfs(int i)//中序输出就是从小到大
{
	if(!q[i].left&&!q[i].right)
	{
		for(re j=1;j<=q[i].num;++j)
		ans[++cnt]=q[i].data;
		return	;
	}
	if(q[i].left)
		dfs(q[i].left);
	for(re j=1;j<=q[i].num;++j)
		ans[++cnt]=q[i].data;
	if(q[i].right)
		dfs(q[i].right);
}

int main()
{
	scanf("%d%d",&n,&m);
	for(re i=1;i<=n;++i)
	{
		scanf("%d",&q[i].data),q[i].num++;
		add(i,1);
	}
	dfs(1);
	for(re i=1;i<=m;++i)
		if(ans[i]<0)
			money-=ans[i];
	printf("%d",money);

}


#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int n,m,q[101],ans;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)
		scanf("%d",&q[i]);
	sort(q+1,q+n+1);
	for(int i=1;i<=m;++i)
		if(q[i]<0)
			ans+=q[i];
	printf("%d",-ans);

}


#include<iostream>
#include<cstdio>
#define re register int
using namespace std;
struct tq
{
	int data,left,right,num;
}q[101];
int n,m,cnt,ans[101],money;
void add(int x,int now)//bst插入
{
	//bst左孩子一定小于父亲，右孩子一定大于父亲
	if(q[x].data<q[now].data)//小于父亲，向左子树插入
	{
		if(q[now].left==0)//没左儿子，直接当儿子
			q[now].left=x;
		else	//有左儿子，向左儿子的子树中插入
			add(x,q[now].left);
	}
	else if(q[x].data>q[now].data)//大于父亲，向右子树插入
	{
		if(q[now].right==0)//没右儿子，直接当儿子
			q[now].right=x;
		else	//有右儿子，向右儿子的子树中插入
			add(x,q[now].right);
	}
	else if(now!=1)
		q[now].num++;	//已经有，计数
}
void dfs(int i)//中序输出就是从小到大
{
	if(!q[i].left&&!q[i].right)
	{
		for(re j=1;j<=q[i].num;++j)
		ans[++cnt]=q[i].data;
		return	;
	}
	if(q[i].left)
		dfs(q[i].left);
	for(re j=1;j<=q[i].num;++j)
		ans[++cnt]=q[i].data;
	if(q[i].right)
		dfs(q[i].right);
}

int main()
{
	scanf("%d%d",&n,&m);
	for(re i=1;i<=n;++i)
	{
		scanf("%d",&q[i].data),q[i].num++;
		add(i,1);
	}
	dfs(1);
	for(re i=1;i<=m;++i)
		if(ans[i]<0)
			money-=ans[i];
	printf("%d",money);

}


#include<iostream>
#include<cstdio>
#define re register int
using namespace std;
struct tq
{
	int data,left,right,num;
}q[101];
int n,m,cnt,ans[101],money;
void add(int x,int now)//bst插入
{
	//bst左孩子一定小于父亲，右孩子一定大于父亲
	if(q[x].data<q[now].data)//小于父亲，向左子树插入
	{
		if(q[now].left==0)//没左儿子，直接当儿子
			q[now].left=x;
		else	//有左儿子，向左儿子的子树中插入
			add(x,q[now].left);
	}
	else if(q[x].data>q[now].data)//大于父亲，向右子树插入
	{
		if(q[now].right==0)//没右儿子，直接当儿子
			q[now].right=x;
		else	//有右儿子，向右儿子的子树中插入
			add(x,q[now].right);
	}
	else	q[now].num++;	//已经有，计数
}
void dfs(int i)//中序输出就是从小到大
{
	if(!q[i].left&&!q[i].right)
	{
		for(re j=1;i<=q[i].num;++j)
		ans[++cnt]=q[i].data;
		return	;
	}
	if(q[i].left)
		dfs(q[i].left);
	for(re j=1;i<=q[i].num;++j)
		ans[++cnt]=q[i].data;
	if(q[i].right)
		dfs(q[i].right);
}

int main()
{
	scanf("%d%d",&n,&m);
	for(re i=1;i<=n;++i)
	{
		scanf("%d",&q[i].data),q[i].num++;
		add(i,1);
	}
	dfs(1);
	for(re i=1;i<=m;++i)
		if(ans[i]<0)
			money-=ans[i];
	printf("%d",money);

}


#include<iostream>
#include<cstdio>
#define re register int
using namespace std;
struct tq
{
	int data,left,right,num;
}q[101];
int n,m,cnt,ans[101],money;
void add(int x,int now)//bst插入
{
	//bst左孩子一定小于父亲，右孩子一定大于父亲
	if(q[x].data<q[now].data)//小于父亲，向左子树插入
	{
		if(q[now].left==0)//没左儿子，直接当儿子
			q[now].left=x;
		else	//有左儿子，向左儿子的子树中插入
			add(x,q[now].left);
	}
	else if(q[x].data>q[now].data)//大于父亲，向右子树插入
	{
		if(q[now].right==0)//没右儿子，直接当儿子
			q[now].right=x;
		else	//有右儿子，向右儿子的子树中插入
			add(x,q[now].right);
	}
	else	q[now].num++;	//已经有，计数
}
void dfs(int i)//中序输出就是从小到大
{
	if(!q[i].left&&!q[i].right)
	{
		for(re j=1;j<=q[i].num;++j)
		ans[++cnt]=q[i].data;
		return	;
	}
	if(q[i].left)
		dfs(q[i].left);
	for(re j=1;j<=q[i].num;++j)
		ans[++cnt]=q[i].data;
	if(q[i].right)
		dfs(q[i].right);
}

int main()
{
	scanf("%d%d",&n,&m);
	for(re i=1;i<=n;++i)
	{
		scanf("%d",&q[i].data),q[i].num++;
		add(i,1);
	}
	dfs(1);
	for(re i=1;i<=m;++i)
		if(ans[i]<0)
			money-=ans[i];
	printf("%d",money);
	for(re i=1;i<=cnt;++i)
		printf("%d ",ans[i]);

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,t;cin>>n>>t;
    vector<int>v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    sort(v.begin(),v.end());
    vector<int>::iterator k=upper_bound(v.begin(),v.end(),0);
    int ans=0;
    if(k-v.begin()<t-1)
    {
        for(int i=0;i<k-v.begin();i++)
        {
            ans=ans+v[i];
        }
    }
    else
    {
        for(int i=0;i<t;i++)
            ans=ans+v[i];
    }
    cout<<-ans;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,t;cin>>n>>t;
    vector<int>v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    sort(v.begin(),v.end());
    vector<int>::iterator k=upper_bound(v.begin(),v.end(),0);
    int ans=0;
    if(k-v.begin()<t-1)
    {
        for(int i=0;i<k-v.begin();i++)
        {
            ans=ans+v[i];
        }
    }
    else
    {
        for(int i=0;i<t;i++)
            ans=ans+v[i];
    }
    if(v[0]>=0)
        ans=0;
    cout<<-ans;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,t,k=n,l=0;
    cin>>n>>m;
    vector<int>a(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++)
    {
        if(a[i]>0)
        {
            k=i;break;
        }
    }

    if((k+1)>=m)
        t=accumulate(a.begin(),a.begin()+m,0);
    else
        t=accumulate(a.begin(),a.begin()+k,0);
    cout<<-t;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,t,k=n,l=0;
    cin>>n>>m;
    vector<int>a(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++)
    {
        if(a[i]>0)
        {
            k=i;break;
        }
    }

    if(k>=m)
        t=accumulate(a.begin(),a.begin()+m,0);
    else
        t=accumulate(a.begin(),a.begin()+k,0);
    cout<<-t;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    vector<int>a(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a.begin(),a.end());
    int t=accumulate(a.begin(),a.begin()+m,0);
    cout<<-t;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,t,k=n,l=0;
    cin>>n>>m;
    vector<int>a(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++)
    {
        if(a[i]>0)
        {
            k=i;break;
        }
    }

    if(k+1>=m)
        t=accumulate(a.begin(),a.begin()+m,0);
    else
        t=accumulate(a.begin(),a.begin()+k,0);
    cout<<-t;
}


#include <bits/stdc++.h>
#define sz size()
#define lcm(a, b) a * b / gcd(a, b)
#define gcd(a, b) __gcd(a, b)

using namespace std;

typedef unsigned long long ull;
typedef long double ld;
typedef long long ll;
typedef string st;
typedef char ch;

const ll N = 1e6;
const ll MOD = 1e9 + 7;
const ll P = 1e6 + 7;
const ll INF = 1e6;

ll n, m, j, b[N], a[N],ans;
int main() {
    cin >> n>> m;
    for(int i = 1;i <= n;++i) {
        cin >> a[i];
        if(a[i] < 0) {
            b[j] = a[i];
            j++;
            }
        }
    sort(b , b + j);
    m+=1;
    for(int i = j;i > 0;--i) {
        ans+=abs(b[i]);
        m--;
            if(m == 0) {
                cout<<ans;
                return 0;
            }
    }
    cout << abs(ans);
    }


#include <bits/stdc++.h>
#define sz size()
#define lcm(a, b) a * b / gcd(a, b)
#define gcd(a, b) __gcd(a, b)

using namespace std;

typedef unsigned long long ull;
typedef long double ld;
typedef long long ll;
typedef string st;
typedef char ch;

const ll N = 1e6;
const ll MOD = 1e9 + 7;
const ll P = 1e6 + 7;
const ll INF = 1e6;

ll n, m, j, b[N], a[N],ans;
int main() {
    cin >> n>> m;
    for(int i = 1;i <= n;++i) {
        cin >> a[i];
        if(a[i] < 0) {
            b[j] = a[i];
            j++;
            }
        }
        //19441
    sort(b , b + j);
    for(int i = 0;i < j;++i) {
        if(m == 0) {
                cout<<ans;
                return 0;
            }
            ans+=abs(b[i]);
        m--;

    }
    cout << abs(ans);
    }


#include <bits/stdc++.h>
#define sz size()
#define lcm(a, b) a * b / gcd(a, b)
#define gcd(a, b) __gcd(a, b)

using namespace std;

typedef unsigned long long ull;
typedef long double ld;
typedef long long ll;
typedef string st;
typedef char ch;

const ll N = 1e6;
const ll MOD = 1e9 + 7;
const ll P = 1e6 + 7;
const ll INF = 1e6;

ll n, m, j, b[N], a[N],ans;
int main() {
    cin >> n>> m;
    for(int i = 1;i <= n;++i) {
        cin >> a[i];
        if(a[i] < 0) {
            b[j] = a[i];
            j++;
            }
        }
    sort(b , b + j);
    reverse(b, b + j);
    for(int i = 0;i < j;++i) {
        if(m == 0) {
                cout<<ans;
                return 0;
            }
            ans+=abs(b[i]);
        m--;

    }
    cout << abs(ans);
    }


#include <bits/stdc++.h>
#define sz size()
#define lcm(a, b) a * b / gcd(a, b)
#define gcd(a, b) __gcd(a, b)

using namespace std;

typedef unsigned long long ull;
typedef long double ld;
typedef long long ll;
typedef string st;
typedef char ch;

const ll N = 1e6;
const ll MOD = 1e9 + 7;
const ll P = 1e6 + 7;
const ll INF = 1e6;

ll n, m, j = 1, b[N], a[N],ans;
int main() {
    cin >> n>> m;
    for(int i = 1;i <= n;++i) {
        cin >> a[i];
        if(a[i] < 0) {
            b[j] = a[i];
            j++;
        }
    }
    sort(b + 1, b + 1 + j);
    for(int i = j;i >= 0;--i) {
        if(m == 0) {
            cout << ans;
            return 0;
        }
        ans+=abs(b[i]);
        m--;
    }
    cout << abs(ans);
}


#include <bits/stdc++.h>
#define sz size()
#define lcm(a, b) a * b / gcd(a, b)
#define gcd(a, b) __gcd(a, b)

using namespace std;

typedef unsigned long long ull;
typedef long double ld;
typedef long long ll;
typedef string st;
typedef char ch;

const ll N = 1e6;
const ll MOD = 1e9 + 7;
const ll P = 1e6 + 7;
const ll INF = 1e6;

ll n, m, j, b[N], a[N],ans;
int main() {
    cin >> n>> m;
    for(int i = 1;i <= n;++i) {
        cin >> a[i];
        if(a[i] < 0) {
            b[j] = a[i];
            j++;
            }
        }
    sort(b , b + j);
    m+=1;
    for(int i = j;i > 0;--i) {
        ans+=abs(b[i]);
        m--;
            if(m == 0) {
                cout<<ans;
                return 0;
            }
    }
    cout << abs(ans)<< ' ' << j;
    }


#include<bits/stdc++.h>
using namespace std;
int main(){
multiset<int> bst;
int n, m, s;
cin>>n>>m;
for(int i=0;i<n;i++){
    cin>>s;
    bst.insert(s);
}
int x=0, y;
s=0;
while(x<m&&bst.empty()!=true){
    if(*bst.begin()<=0&&x<m){
    s=s-((bst.count(*bst.begin()))*(*bst.begin()));
    x=x+bst.count(*bst.begin());
    y=*bst.begin();
    bst.erase(*bst.begin());
    }
    else{
    bst.erase(*bst.begin());}
}
int j;
if(x>m){
j=x-m;
s=s+j*y;
}
cout<<s;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
multiset<int> bst;
int n, m, s;
cin>>n>>m;
for(int i=0;i<n;i++){
    cin>>s;
    bst.insert(s);
}
int x=0, y;
s=0;
while(x<m&&bst.empty()!=true){
    if(*bst.begin()<=0&&x<m){
    s=s-((bst.count(*bst.begin()))*(*bst.begin()));
    x=x+bst.count(*bst.begin());
    y=*bst.begin();
    bst.erase(*bst.begin());
    }
    else{
    bst.erase(*bst.begin());}
}
int j;
if(x!=m){
j=x-m;
s=s+j*y;
}
cout<<s;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
multiset<int> bst;
int n, m, s;
cin>>n>>m;
for(int i=0;i<n;i++){
    cin>>s;
    bst.insert(s);
}
int x=0;
s=0;
while(x<=m&&bst.empty()!=true){
    if(*bst.begin()<=0){
    s=s-((bst.count(*bst.begin()))*(*bst.begin()));
    x=x+bst.count(*bst.begin());
    if(x<m){
    bst.erase(*bst.begin());
    }}
    else{
    bst.erase(*bst.begin());}
}
int j;
if(x!=m&&bst.empty()!=true){
j=x-m;
s=s-j*(*bst.begin());
}
cout<<s;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
multiset<int> bst;
int n, m, s;
cin>>n>>m;
for(int i=0;i<n;i++){
    cin>>s;
    bst.insert(s);
}
int x=0, y;
s=0;
while(x<m&&bst.empty()!=true){
    if(*bst.begin()<=0&&x<m){
    s=s-((bst.count(*bst.begin()))*(*bst.begin()));
    x=x+bst.count(*bst.begin());
    y=*bst.begin();
    bst.erase(*bst.begin());
    }
    else{
    bst.erase(*bst.begin());}
}
int j;
if(x!=m&&bst.empty()!=true){
j=x-m;
s=s-j*y;
}
cout<<s;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
multiset<int> bst;
int n, m, s;
cin>>n>>m;
for(int i=0;i<n;i++){
    cin>>s;
    bst.insert(s);
}
int x=0;
s=0;
while(x<m){
    s=s-((bst.count(*bst.begin()))*(*bst.begin()));
    x=x+bst.count(*bst.begin());
    if(x<=m){
    bst.erase(*bst.begin());}
}
int j;
if(x!=m){
j=x-m;
s=s-j*(*bst.begin());
}
cout<<s;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
multiset<int> bst;
int n, m, s;
cin>>n>>m;
for(int i=0;i<n;i++){
    cin>>s;
    bst.insert(s);
}
int x=0;
s=0;
while(x<=m&&bst.empty()!=true){
    if(*bst.begin()<=0){
    s=s-((bst.count(*bst.begin()))*(*bst.begin()));
    x=x+bst.count(*bst.begin());
    bst.erase(*bst.begin());
    }
    else{
    bst.erase(*bst.begin());
}}
int j;
if(x!=m&&bst.empty()==true){
j=x-m;
s=s-j*(*bst.begin());
}
cout<<s;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m;
cin>>n>>m;
double a[n];
for(int i=0; i<n; ++i){
	cin>>a[i];
}
double b[m];
double k,sum=0,max=-10000000000;
sort(a,a+n);
for(int i=0; i<m; ++i){
	sum=sum-a[i];
	if(sum>max) max=sum;
	else if(sum<max){
		cout<<max;
		return 0;
	}
}
cout<<sum;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m;
cin>>n>>m;
double a[n];
for(int i=0; i<n; ++i){
	cin>>a[i];
}
double b[m];
double k,sum=0,max=-10000000000;
sort(a,a+n);
for(int i=0; i<m; ++i){
	sum=sum-a[i];
	if(sum>max) max=sum;
	if(sum<max){
		cout<<max;
		return 0;
	}
}
cout<<sum;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(x) x.begin(), x.end()

typedef long long ll;

long double const PI = acosl(-1);
const int INF=1E9 + 4;
const int MAXN=1e5 + 123;
const long double EPS = 3e-16;
const ll MOD=1e9 + 7;

vector<int>g;
bool used[MAXN];

int a[MAXN];
int b[3001];
bool c[101][101];
int x[26];

bool fl;
void solve(){
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a,a+n);
	ll ans = 0;
	int i = 0;
	while(a[i] <= 0 && m--){
		ans -= a[i];
		i++;
	}
	cout << ans;
}

int main() {
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int t = 1;
    //cin >> t;
	while(t--) solve();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fact(int n){
	if(n=0) return 1;
	int k=1;
	for(int i=1;i<n;i++){
		k*=i;
	}
	return k;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m;
cin>>n>>m;
double a[n];
for(int i=0; i<n; ++i){
	cin>>a[i];
}
double b[m];
double k,sum=0,max=-1;
sort(a,a+n);
for(int i=0; i<m; ++i){
	sum=sum-a[i];
}
cout<<sum;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m;
cin>>n>>m;
double a[n];
for(int i=0; i<n; ++i){
	cin>>a[i];
	a[i]=a[i]*-1;
}
double b[m];
double k,sum=0,max=-1;
for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
		for(int k=0;k<n;k++){
			if(i!=j && i!=k && j!=k){
				sum=a[i]+a[j]+a[k];
				if(sum>max)max=sum;
			}
		}
	}
}
cout<<max;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m;
cin>>n>>m;
double a[n];
for(int i=0; i<n; ++i){
	cin>>a[i];
}
double b[m];
double k;
sort(a,a+n);
double sum=0;
double max=0;
for(int i=0; i<m; ++i){
	sum=sum-a[i];
	if(sum>max) max=sum;
	if(sum<max){
		cout<<max;
		return 0;
	}
}
cout<<sum;
return 0;
}


#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;

int main ()
{
	int size, m,sum=0, x=0;
	cin>>size;
	cin>>m;
	int *price;
	price = new int [size];
	for (int i=0; i<size;i++)
	{	 cin>>price[i];
	}
	sort(price,price+size);
	//for(int x= 0; x<m;x++)
	{
	for (int i=0; i<size; i++)
	{ while(x<m){
		if(price[i]<0)
	{
	    sum+=price[i];
	    x++;
	}
	    }
	}
	}
	sum=abs(sum);

	cout<<sum;

	return 0;

}


#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>

using namespace std;

int main ()
{
	int size, m,sum=0;
	cin>>size;
	cin>>m;
	int *price;
	price = new int [size];
	for (int i=0; i<size;i++)
	{	 cin>>price[i];
	}
	for (int i=0; i<size; i++)
	{
		if(price[i]<0)
			sum+=price[i];
	}
	sum=sum*-1;
	cout<<sum;

	return 0;

}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n, m, price[10000];
    cin >> n >> m;

    for (int i = 0; i < n; ++i)
    {
        cin >> price[i];
    }
    sort(price, price + n);

    int s(0);
    for (int i = 0; i < m; ++i)
    {
        if (price[i] >= 0)
        {
            break;
        }
        s += price[i];
    }
    cout << -s << endl;
    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n, m, price[80];
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
    {
        cin >> price[i];
    }
    sort(price, price + n);

    int s(0);
    for (int i = 0; i < m; ++i)
    {
        if (price[i] >= 0)
        {
            break;
        }
        s += price[i];
    }
    cout << -s << endl;
    return 0;
}


#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;

int main ()
{
	int size, m,sum=0, x=0;
	cin>>size;
	cin>>m;

	int *price;
	price = new int [size];

	for (int i=0; i<size;i++)
	{
	    cin>>price[i];
	}

	sort(price,price+size);

	for (int i=0; i<size; i++)
	{
		if(price[i]<0)
	    {
	    sum+=price[i];
	    x++;
	    }

	}

	sum=abs(sum);

	cout<<sum;

	return 0;

}


#include <bits/stdc++.h>
#define li 5005
#define N 1000005
using namespace std;
int n,k,A[li],tot[N],tut[N];
int main(){
    scanf("%d %d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&A[i]);
    sort(A+1,A+n+1);
    for(int i=1;i<=n;i++){
        for(int j=i-1;j>=1;j--){
            tot[A[i]-A[j]]++;
        }
    }
    for(int i=1;i<N;i++){
        int res=0;
        int cev=0;
        for(int j=i;j<N;j+=i){
            res+=tot[j];
        }
        if(res>(k*(k+1))/2) continue;
        for(int j=1;j<=n;j++){
            if(tut[A[j]%i]==i) cev++;
            tut[A[j]%i]=i;
        }
        if(cev<=k){
            printf("%d\n",i);
            return 0;
        }
    }
    return 0;
}


//Konrad Paluszek, University of Warsaw (former XIV LO Staszic)
# include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define FOR(i, b, e) for (auto i = (b); i <= (e); ++i)
#define REP(i, n) for (urs(n) i = 0; i < (n); ++i)
#define FORD(i, b, e) for (auto i = (b); i >= (int)(e); --i)
#define UNTIL(t) while (clock() < (t) * CLOCKS_PER_SEC)
#define ALL(r) (r).begin(), (r).end()
#define FS(r) r.first, r.second
#define MAKE(b, e) <urs(*(b))>(b, e)
#define sim template <class c
#define ros return o
#define rans return ans
#define forbits(i, m) if (m) for (urs(m) i = ctz(m), quq = m; quq; quq ^= ((decltype(m))1 << i), i = ctz(quq))
#define fordbits(i, m) if (m) for (urs(m) i = 8 * sizeof(m) - clz(m) - 1, quq = m; quq; quq ^= ((decltype(m))1 << i), i = 8 * sizeof(m) - clz(quq) - 1)
#define urs(r) typename decay<decltype(r)>::type
#define hur(f, g) int f(unt a) {return g(a);} int f(int a) {return g(a);} \
int f(ll a) {return g##ll(a);} int f(ull a) {return g##ll(a);} int f(long a){return f((ll)a);}; int f(unsigned long a){return f((ull)a);}
using ll = long long; using ld = long double; using ull = unsigned long long;using pii = pair <int, int>;
using vpii = vector <pii>; using unt = unsigned int;sim> using min_queue = priority_queue<c, vector<c>, greater<c>>;
template <typename T>using ordered_set =tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
hur(popc, __builtin_popcount) hur(ctz, __builtin_ctz) hur(clz, __builtin_clz)
sim,class N>bool mini(c&o,N h){if(o>h)ros=h,1;return 0;}sim,class N>bool maxi(c&o,N h){if(o<h)ros=h,1;return 0;}
#ifdef LOCAL
string vqx(int l, string f){stringstream o;o<<"\033[1;"<<30+l%8<<"m"<<f<<"#"<<l<<": \033["<<30+(int)(l*3.125)%8<<"m";ros.str();}
ostream & operator<<(ostream &d, __int128 x) {int dig[50],c=0; if (x < 0) d << "-",x = -x;do {dig[c++] = x % 10;x /= 10;} while (x);while (c)d << dig[--c]; return d;}
ostream & operator<<(ostream &d, __uint128_t x) {int dig[50],c=0; do {dig[c++] = x % 10;x /= 10;} while (x);while (c)d << dig[--c]; return d;}
#define oor >ostream &operator<<(ostream &o,
#define bnt ;}sim> struct
sim,class N oor pair<c,N>u){ros<<"<"<<u.first<<", "<<u.second<<">";}
sim,typename=typename enable_if<!is_same<c,string>::value,urs(c().end())>::type oor c u){
int q=0;o<<"{";for(auto e:u)o<<", "+2*!q++<<e;ros<<"}";} void dor(bool x){cerr<<dec<<"\033[0m"<<endl;}
sim,class...N>void dor(int w,c x,N...y){cerr<<boolalpha<<x<<"; "+2*w;dor(0,y...);}
#define debug(c...)::dor(1,vqx(__LINE__,__FUNCTION__),c);
#define rcu m);}g(+) g(-) g(*) g(/) g(%) g(<<) g(>>) g(^) g(|) g(&) g(>=) g(<=) g(>) g(<) g(!=) g(==)
#define zub(h,t,n...) class N> auto operator h(n u)->nep<urs(t)> {return ngy(t,
sim>string bte(c u){stringstream o;o<<boolalpha<<u;ros.str()bnt nep;sim>c yyo(nep<c>);sim>nep<c>ngy(c,string,int m=0);
sim>c yyo(c o){ros bnt nep{c v;string d;int m; nep<c>mask(){return ngy(v,d,1);}
#define g(o) template<zub(o, v o u, N) "(" + bte(*this) + ") " #o " (" + bte(u) + ")", m);}
template<zub([],v[yyo(u)],N)d+"["+bte(u)+"]",rcu};sim>nep<c>ngy(c v,string d,int m){return nep<c>{v,d,m};}
sim>c yyo(nep<c> o){ros.v;}sim>int uhn(c){return 0;}sim>int uhn(nep<c>o){ros.m;}
#define ccy(r...) sim> class enable_if<r is_integral<c>::value,string>::type ema(c u){
ccy(!)return bte(u);}ccy()stringstream o;o<<"[";int q=0;forbits(i,u)o<<", "+2*!q++<<i;ros.str()+"]";}
#undef g
#define g(o) sim, zub(o, yyo(p) o u.v, c p, nep<N>) "(" + bte(p) + ") " #o " (" + bte(u) + ")", uhn(p) + u.m);}
sim>string bte(nep<c>o){ros.d+" = "+(o.m?ema(o.v):bte(o.v));}
sim oor nep<c>m){ros<<bte(rcu sim> nep<c> ngy(nep<c> o,string d="",int m=0){ros;}
#undef g
#define imie(a...) ngy(a, #a)
#define imask(a...) ngy(a, #a, 1)
#define range_v(u, g, c) ngy(list<urs(u[0])>(&u[yyo(g)], &u[yyo(c)] + 1), #u "[" + bte(g) + "..." + bte(c) + "]")
#define range(i, j) ngy(list<urs(*i)>(i, j), "[" #i "..." #j ")")
#define arr(a, i) imie(a)[imie(i)]
#define arr2(a, i, j) imie(a)[imie(i)][imie(j)]
#define arr3(a, i, j, k) imie(a)[imie(i)][imie(j)][imie(k)]
#define arr4(a, i, j, k, q) imie(a)[imie(i)][imie(j)][imie(k)][imie(q)]
#define ckx(o) template<zub(o, o yyo(u), nep<N>) #o "(" + bte(u) + ")", u.m);}
ckx(+)ckx(-)ckx(!)ckx(~)
#else
#define debug(...)
#endif
#define vsv sim, class d, class e
#define nop(o,c,r,l...) auto operator o(c a, r b)-> decltype(make_pair(l)) {return {l};}
#define pcg(o) vsv, class f> nop(o, pair <c u d>, pair <e u f>, a.first o b.first, a.second o b.second) \
vsv,class = typename enable_if<!is_base_of<ios_base, c>::value>::type> nop(o, c, pair<d u e>, a o b.first, a o b.second) \
vsv> nop(o, pair<c u d>, e, a.first o b, a.second o b)
#define clp(o) pcg(o) \
vsv> void operator o##= (pair <c,d> & a, e b) {a.first o##= b; a.second o##= b;} \
vsv, class f> void operator o##= (pair <c,d> & a, pair <e,f> b) {a.first o##= b.first; a.second o##= b.second;}
#define syd(o) sim, class d> auto operator o(pair<c, d> e) -> decltype(make_pair(o e.first, o e.second)) {return {o e.first, o e.second};}
#define u ,
clp(+)clp(-)clp(*)clp(/)clp(%)clp(^)clp(|)clp(>>)clp(<<)clp(&)pcg(&&)pcg(||)syd(-)syd(+)syd(~)syd(!)
#undef u
ull mix(ull x){x += 0x9e3779b97f4a7c15;x=(x^(x>>30))*0xbf58476d1ce4e5b9;x=(x^(x>>27))*0x94d049bb133111eb;return x^(x>>31);}
sim,class n>using gyv=c;namespace std{sim,class n>struct hash<pair<c,n>>{size_t operator()(const pair<c,n>&x)const{
return mix(hash<c>()(x.first))^hash<n>()(x.second);}};sim>struct hash<gyv<c, typename c::value_type>>
{size_t operator()(const c&x)const{size_t ans = x.size();for (auto &e : x) ans = mix(ans ^ hash<typename c::value_type>()(e));rans;}};};
#ifndef LOCAL
sim, class m> using _un0rDer3d_M4P = cc_hash_table<c, m, hash<c>>;
#define unordered_map _un0rDer3d_M4P
#endif
#define next __n3kst
#define prev __prew
#define tree __tRe3
#define left __l3fT
#define right __Ri9ht
void fre(string c) {
#if !defined(LOCAL) && !defined(LOCAL2)
	freopen((c+".in").c_str(), "r", stdin);
	freopen((c+".out").c_str(), "w", stdout);
#endif
}
const int vax = 1e6 + 44, nax = 5e3 + 44;
int n, k;
int touched[nax];
int cou[nax];
int a[nax];
void test(int m) {
	static int timer = 0;
	timer++;
	int skipped = 0;
	REP(i, n) {
		int x = a[i] % m;
		if (touched[x] == timer) {
			skipped++;
			if (skipped > k) return;
		}
		touched[x] = timer;
	}
	printf("%d\n", m);
	exit(0);
}
int main() {
	scanf("%d%d", &n, &k);
	REP(i, n) scanf("%d", a + i);
	REP(i, n) REP(j, i) cou[abs(a[i] - a[j])]++;
	FOR(m, 1, nax - 1) {
		int c = 0;
		int bound = k * (k + 1) / 2;
		for (int v = m; v < nax && c <= bound; v += m)
			c += cou[v];
		if (c <= bound) test(m);
	}
	assert(false);
}


//Konrad Paluszek, University of Warsaw (former XIV LO Staszic)
# include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define FOR(i, b, e) for (auto i = (b); i <= (e); ++i)
#define REP(i, n) for (urs(n) i = 0; i < (n); ++i)
#define FORD(i, b, e) for (auto i = (b); i >= (int)(e); --i)
#define UNTIL(t) while (clock() < (t) * CLOCKS_PER_SEC)
#define ALL(r) (r).begin(), (r).end()
#define FS(r) r.first, r.second
#define MAKE(b, e) <urs(*(b))>(b, e)
#define sim template <class c
#define ros return o
#define rans return ans
#define forbits(i, m) if (m) for (urs(m) i = ctz(m), quq = m; quq; quq ^= ((decltype(m))1 << i), i = ctz(quq))
#define fordbits(i, m) if (m) for (urs(m) i = 8 * sizeof(m) - clz(m) - 1, quq = m; quq; quq ^= ((decltype(m))1 << i), i = 8 * sizeof(m) - clz(quq) - 1)
#define urs(r) typename decay<decltype(r)>::type
#define hur(f, g) int f(unt a) {return g(a);} int f(int a) {return g(a);} \
int f(ll a) {return g##ll(a);} int f(ull a) {return g##ll(a);} int f(long a){return f((ll)a);}; int f(unsigned long a){return f((ull)a);}
using ll = long long; using ld = long double; using ull = unsigned long long;using pii = pair <int, int>;
using vpii = vector <pii>; using unt = unsigned int;sim> using min_queue = priority_queue<c, vector<c>, greater<c>>;
template <typename T>using ordered_set =tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
hur(popc, __builtin_popcount) hur(ctz, __builtin_ctz) hur(clz, __builtin_clz)
sim,class N>bool mini(c&o,N h){if(o>h)ros=h,1;return 0;}sim,class N>bool maxi(c&o,N h){if(o<h)ros=h,1;return 0;}
#ifdef LOCAL
string vqx(int l, string f){stringstream o;o<<"\033[1;"<<30+l%8<<"m"<<f<<"#"<<l<<": \033["<<30+(int)(l*3.125)%8<<"m";ros.str();}
ostream & operator<<(ostream &d, __int128 x) {int dig[50],c=0; if (x < 0) d << "-",x = -x;do {dig[c++] = x % 10;x /= 10;} while (x);while (c)d << dig[--c]; return d;}
ostream & operator<<(ostream &d, __uint128_t x) {int dig[50],c=0; do {dig[c++] = x % 10;x /= 10;} while (x);while (c)d << dig[--c]; return d;}
#define oor >ostream &operator<<(ostream &o,
#define bnt ;}sim> struct
sim,class N oor pair<c,N>u){ros<<"<"<<u.first<<", "<<u.second<<">";}
sim,typename=typename enable_if<!is_same<c,string>::value,urs(c().end())>::type oor c u){
int q=0;o<<"{";for(auto e:u)o<<", "+2*!q++<<e;ros<<"}";} void dor(bool x){cerr<<dec<<"\033[0m"<<endl;}
sim,class...N>void dor(int w,c x,N...y){cerr<<boolalpha<<x<<"; "+2*w;dor(0,y...);}
#define debug(c...)::dor(1,vqx(__LINE__,__FUNCTION__),c);
#define rcu m);}g(+) g(-) g(*) g(/) g(%) g(<<) g(>>) g(^) g(|) g(&) g(>=) g(<=) g(>) g(<) g(!=) g(==)
#define zub(h,t,n...) class N> auto operator h(n u)->nep<urs(t)> {return ngy(t,
sim>string bte(c u){stringstream o;o<<boolalpha<<u;ros.str()bnt nep;sim>c yyo(nep<c>);sim>nep<c>ngy(c,string,int m=0);
sim>c yyo(c o){ros bnt nep{c v;string d;int m; nep<c>mask(){return ngy(v,d,1);}
#define g(o) template<zub(o, v o u, N) "(" + bte(*this) + ") " #o " (" + bte(u) + ")", m);}
template<zub([],v[yyo(u)],N)d+"["+bte(u)+"]",rcu};sim>nep<c>ngy(c v,string d,int m){return nep<c>{v,d,m};}
sim>c yyo(nep<c> o){ros.v;}sim>int uhn(c){return 0;}sim>int uhn(nep<c>o){ros.m;}
#define ccy(r...) sim> class enable_if<r is_integral<c>::value,string>::type ema(c u){
ccy(!)return bte(u);}ccy()stringstream o;o<<"[";int q=0;forbits(i,u)o<<", "+2*!q++<<i;ros.str()+"]";}
#undef g
#define g(o) sim, zub(o, yyo(p) o u.v, c p, nep<N>) "(" + bte(p) + ") " #o " (" + bte(u) + ")", uhn(p) + u.m);}
sim>string bte(nep<c>o){ros.d+" = "+(o.m?ema(o.v):bte(o.v));}
sim oor nep<c>m){ros<<bte(rcu sim> nep<c> ngy(nep<c> o,string d="",int m=0){ros;}
#undef g
#define imie(a...) ngy(a, #a)
#define imask(a...) ngy(a, #a, 1)
#define range_v(u, g, c) ngy(list<urs(u[0])>(&u[yyo(g)], &u[yyo(c)] + 1), #u "[" + bte(g) + "..." + bte(c) + "]")
#define range(i, j) ngy(list<urs(*i)>(i, j), "[" #i "..." #j ")")
#define arr(a, i) imie(a)[imie(i)]
#define arr2(a, i, j) imie(a)[imie(i)][imie(j)]
#define arr3(a, i, j, k) imie(a)[imie(i)][imie(j)][imie(k)]
#define arr4(a, i, j, k, q) imie(a)[imie(i)][imie(j)][imie(k)][imie(q)]
#define ckx(o) template<zub(o, o yyo(u), nep<N>) #o "(" + bte(u) + ")", u.m);}
ckx(+)ckx(-)ckx(!)ckx(~)
#else
#define debug(...)
#endif
#define vsv sim, class d, class e
#define nop(o,c,r,l...) auto operator o(c a, r b)-> decltype(make_pair(l)) {return {l};}
#define pcg(o) vsv, class f> nop(o, pair <c u d>, pair <e u f>, a.first o b.first, a.second o b.second) \
vsv,class = typename enable_if<!is_base_of<ios_base, c>::value>::type> nop(o, c, pair<d u e>, a o b.first, a o b.second) \
vsv> nop(o, pair<c u d>, e, a.first o b, a.second o b)
#define clp(o) pcg(o) \
vsv> void operator o##= (pair <c,d> & a, e b) {a.first o##= b; a.second o##= b;} \
vsv, class f> void operator o##= (pair <c,d> & a, pair <e,f> b) {a.first o##= b.first; a.second o##= b.second;}
#define syd(o) sim, class d> auto operator o(pair<c, d> e) -> decltype(make_pair(o e.first, o e.second)) {return {o e.first, o e.second};}
#define u ,
clp(+)clp(-)clp(*)clp(/)clp(%)clp(^)clp(|)clp(>>)clp(<<)clp(&)pcg(&&)pcg(||)syd(-)syd(+)syd(~)syd(!)
#undef u
ull mix(ull x){x += 0x9e3779b97f4a7c15;x=(x^(x>>30))*0xbf58476d1ce4e5b9;x=(x^(x>>27))*0x94d049bb133111eb;return x^(x>>31);}
sim,class n>using gyv=c;namespace std{sim,class n>struct hash<pair<c,n>>{size_t operator()(const pair<c,n>&x)const{
return mix(hash<c>()(x.first))^hash<n>()(x.second);}};sim>struct hash<gyv<c, typename c::value_type>>
{size_t operator()(const c&x)const{size_t ans = x.size();for (auto &e : x) ans = mix(ans ^ hash<typename c::value_type>()(e));rans;}};};
#ifndef LOCAL
sim, class m> using _un0rDer3d_M4P = cc_hash_table<c, m, hash<c>>;
#define unordered_map _un0rDer3d_M4P
#endif
#define next __n3kst
#define prev __prew
#define tree __tRe3
#define left __l3fT
#define right __Ri9ht
void fre(string c) {
#if !defined(LOCAL) && !defined(LOCAL2)
	freopen((c+".in").c_str(), "r", stdin);
	freopen((c+".out").c_str(), "w", stdout);
#endif
}
const int vax = 1e6 + 44, nax = 5e3 + 44;
int n, k;
int touched[vax];
int cou[vax];
int a[nax];
void test(int m) {
	static int timer = 0;
	timer++;
	int skipped = 0;
	REP(i, n) {
		int x = a[i] % m;
		if (touched[x] == timer) {
			skipped++;
			if (skipped > k) return;
		}
		touched[x] = timer;
	}
	printf("%d\n", m);
	exit(0);
}
int main() {
	scanf("%d%d", &n, &k);
	REP(i, n) scanf("%d", a + i);
	REP(i, n) REP(j, i) cou[abs(a[i] - a[j])]++;
	FOR(m, 1, vax - 1) {
		int c = 0;
		int bound = k * (k + 1) / 2;
		for (int v = m; v < vax && c <= bound; v += m)
			c += cou[v];
		if (c <= bound) test(m);
	}
	assert(false);
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <utility>
#include <complex>
#include <functional>
#include <bitset>
#include <time.h>
#include <assert.h>
#define ff first
#define ss second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pii;
template <class T> inline void umin(T &a,T b){a=min(a,b);}
template <class T> inline void umax(T &a,T b){a=max(a,b);}
const int INF=0x3f3f3f3f;
LL mod=1e9+7;
const int N=5005;
int a[5005];
int b[1000005];
int vis[1000005];
int n,m;

int main() {
#ifndef ONLINE_JUDGE
	//freopen("51nod_Problem_1217_Test_13_In.txt","r",stdin);
#endif

	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	if(m>=n){
		puts("1");
		return 0;
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			b[a[j]-a[i]]++;
		}
	}
	for(int i=n-m;;i++){
		int cnt=0;
		for(int j=i;j<=1000000;j+=i){
			cnt+=b[j];
		}
		int sb=0;
		if(cnt>m*(m+1)/2)goto M1;
		for(int j=0;j<n;j++){
			int t=a[j]%i;
			if(vis[t]==i)sb++;
			else vis[t]=i;
			if(sb>m)goto M1;
		}
		printf("%d\n",i);
		return 0;
		M1:;
	}
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <string.h>
using namespace std;
int aa[1000006],bb[5555],cc[1000006];
int main ()
{
    freopen ("zz.txt","r",stdin);
    int n,k,t=-1;
    cin >>n>>k;
    for (int i=0;i<n;i++)
    {
        scanf ("%d",bb+i);
        if (bb[i]>t) t=bb[i];
    }
    memset(aa,0,sizeof(aa));
    for (int i=0;i<n;i++)
        for  (int j=i-1;j>=0;j--)
            aa[abs(bb[i]-bb[j])]++;
    int m=1;
    while (1)
    {
        int a=0,b=0;
        for (int i=m;i<=t+1;i+=m)
            a+=aa[i];
        if (a>k*(k+1)/2)
        {
            m++;
            continue;
        }
        for (int i=0;i<n;i++)
        {
            if (cc[bb[i]%m]==m)
            {
                b++;
                if (b>k) break;
            }
            else cc[bb[i]%m]==m;
        }
        if (b<=k) break;
        m++;
    }
    cout <<m<<endl;
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <string.h>
using namespace std;
int aa[1000006],bb[5555],cc[1000006];
int main ()
{
    //freopen ("zz.txt","r",stdin);
    int n,k,t=-1;
    cin >>n>>k;
    for (int i=0;i<n;i++)
    {
        scanf ("%d",bb+i);
        if (bb[i]>t) t=bb[i];
    }
    memset(aa,0,sizeof(aa));
    for (int i=0;i<n;i++)
        for  (int j=i-1;j>=0;j--)
            aa[abs(bb[i]-bb[j])]++;
    int m=1;
    while (1)
    {
        int a=0,b=0;
        for (int i=m;i<=t+1;i+=m)
            a+=aa[i];
        if (a>k*(k+1)/2)
        {
            m++;
            continue;
        }
        for (int i=0;i<n;i++)
        {
            //cout <<bb[i]%m<<" "<<b<<endl;
            if (cc[bb[i]%m]==m)
            {
                b++;
                if (b>k) break;
            }
            else cc[bb[i]%m]=m;
        }
        //cout <<endl;
        if (b<=k) break;
        m++;
    }
    cout <<m<<endl;
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <string.h>
using namespace std;
int aa[1000006],bb[5555],cc[1000006];
int main ()
{
    //freopen ("zz.txt","r",stdin);
    int n,k,t=-1;
    cin >>n>>k;
    for (int i=0;i<n;i++)
    {
        scanf ("%d",bb+i);
        if (bb[i]>t) t=bb[i];
    }
    memset(aa,0,sizeof(aa));
    for (int i=0;i<n;i++)
        for  (int j=i-1;j>=0;j--)
            aa[abs(bb[i]-bb[j])]++;
    int m=1;
    while (1)
    {
        int a=0,b=0;
        for (int i=m;i<=t+1;i+=m)
            a+=aa[i];
        if (a>k*(k+1)/2)
        {
            m++;
            continue;
        }
        for (int i=0;i<n;i++)
        {
            if (cc[bb[i]%m]==m)
            {
                b++;
                if (b>k) break;
            }
            else cc[bb[i]%m]==m;
        }
        if (b<=k) break;
        m++;
    }
    cout <<m<<endl;
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>

using namespace std;

const int maxn = 1000000+5;

int a[maxn],n,k,re[maxn],h[maxn];

int main(){
	scanf("%d%d",&n,&k);
	int max = -1;
	memset(re,0,sizeof(re));
	memset(h,0,sizeof(h));
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(max < a[i])max = a[i];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<i;j++)
		{
			int tmp = a[i] - a[j]>0?a[i]-a[j]:a[j]-a[i];
			h[tmp]++;
		}
	}

	int res, flag =1;

	for(int m=1;m<=max+1;m++)
	{
			int tk = k;
			int sum = 0;
			flag = 1;
			for(int i=m;i<=1e6;i+=m)
			{
				sum+=h[i];
				if(sum>k*(k+1)/2)break;
			}
			if(sum>k*(k+1)/2)continue;
			res = m;
			for(int i=1; i<=n; i++)
			{
				if(!re[a[i]%res])re[a[i]%res]++;
				else
				{
					tk--;
					if(tk<0){flag =0;break;}
				}
			}
			if(flag)break;
	}
	printf("%d\n",res);
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>

using namespace std;

const int maxn = 1000000+5;

int a[maxn],n,k,re[maxn],h[maxn];

int main(){
	scanf("%d%d",&n,&k);
	int max = -1;
	memset(re,0,sizeof(re));
	memset(h,0,sizeof(h));
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(max < a[i])max = a[i];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<i;j++)
		{
			int tmp = a[i] - a[j]>0?a[i]-a[j]:a[j]-a[i];
			h[tmp]++;
		}
	}

	int res, flag =1;

	for(int m=1;m<=max+1;m++)
	{
			int tk = k;
			int sum = 0;
			flag = 1;
			for(int i=m;i<=1e6;i+=m)
			{
				sum+=h[i];
				if(sum>k*(k+1)/2)break;
			}
			if(sum>k*(k+1)/2)continue;
			res = m;
			for(int i=1; i<=n; i++)
			{
				if(!re[a[i]%res])re[a[i]%res]++;
				else
				{
					tk--;
					if(tk<0){flag =0;break;}
				}
			}
			memset(re,0,sizeof(re));
			if(flag)break;
	}
	printf("%d\n",res);
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>

using namespace std;

const int maxn = 1000000+5;

int a[maxn],n,k,re[maxn],h[maxn];

int main(){
	scanf("%d%d",&n,&k);
	if(k==n||k+1==n){printf("1\n");return 0;}
	int max = -1;
	memset(re,0,sizeof(re));
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(max < a[i])max = a[i];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<i;j++)
		{
			int tmp = a[i] - a[j]>0?a[i]-a[j]:a[j]-a[i];
			h[tmp]++;
		}
	}

	int res, flag =1;

	for(int m=1;m<=max+1;m++)
	{
			int sum = 0;
			flag = 1;
			for(int i=m;i<=1e6;i+=m)
			{
				sum+=h[i];
				if(sum>k*(k+1)/2)break;
			}
			if(sum>k*(k+1)/2)continue;
			res = m;
			for(int i=1;i<=n;i++)
			{
				if(!re[a[i]%res])re[a[i]%res]++;
				else
				{
					k--;
					if(k<0){flag =0;break;}
				}
			}
			if(flag)break;
	}
	printf("%d\n",res);
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>

using namespace std;

const int maxn = 1000000+5;

int a[maxn],n,k,re[maxn],h[maxn];

int main(){
	scanf("%d%d",&n,&k);
	int max = -1;
	memset(re,0,sizeof(re));
	memset(h,0,sizeof(h));
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(max < a[i])max = a[i];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<i;j++)
		{
			int tmp = a[i] - a[j]>0?a[i]-a[j]:a[j]-a[i];
			h[tmp]++;
		}
	}

	int res, flag =1;

	for(int m=1;m<=max+1;m++)
	{
			int tk = k;
			int sum = 0;
			flag = 1;
			for(int i=m;i<=1e6;i+=m)
			{
				sum+=h[i];
				if(sum>k*(k+1)/2)break;
			}
			if(sum>k*(k+1)/2)continue;
			res = m;
			for(int i=1; i<=n; i++)
			{
				if(!re[a[i]%res])re[a[i]%res]++;
				else
				{
					tk--;
					if(tk<0){flag =0;break;}
				}
			}
			for(int i=1;i<=n;i++)
			{
				re[a[i]%m]=0;
			}
			if(flag)break;
	}
	printf("%d\n",res);
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>

using namespace std;

const int maxn = 1000000+5;

int a[maxn],n,k,re[maxn],h[maxn];

int main(){
	scanf("%d%d",&n,&k);
	int max = -1;
	memset(re,0,sizeof(re));
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(max < a[i])max = a[i];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<i;j++)
		{
			int tmp = a[i] - a[j]>0?a[i]-a[j]:a[j]-a[i];
			h[tmp]++;
		}
	}

	int res;

	for(int m=1;m<=max+1;m++)
	{
		int tk = k;
		for(int i=m; i<=1e6; i+=m)
		{
			if(h[i]>=1)tk-=h[i];
			if(tk<0)break;
		}
		if(tk>=0){res=m;break;}
	}
	printf("%d\n",res);
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>

using namespace std;

const int maxn = 1000000+5;

int a[maxn],n,k,re[maxn],h[maxn];

int main(){
	scanf("%d%d",&n,&k);
	if(k==n||k+1==n){printf("1\n");return 0;}
	int max = -1;
	memset(re,0,sizeof(re));
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(max < a[i])max = a[i];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<i;j++)
		{
			int tmp = a[i] - a[j]>0?a[i]-a[j]:a[j]-a[i];
			h[tmp]++;
		}
	}

	int res;

	for(int m=1;m<=max+1;m++)
	{
		int tk = k;
		for(int i=m; i<=1e6; i+=m)
		{
			if(h[i]>=1)tk-=h[i];
			if(tk<0)break;
		}
		if(tk>=0){res=m;break;}
	}
	printf("%d\n",res);
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define FOR(v,p,k) for(int v=p;v<=k;++v)
#define FORD(v,p,k) for(int v=p;v>=k;--v)
#define REP(i,n) for(int i=0;i<(n);++i)
#define VAR(v,i) __typeof(i) v=(i)
#define FORE(i,c) for(__typeof(c.begin()) i=(c.begin());i!=(c).end();++i)
#define PB push_back
#define ST first
#define ND second
#define SZ(x) (int)(x).size()
#define ALL(c) c.begin(),c.end()
#define ZERO(x) memset(x,0,sizeof(x))

vector<int> df[1000005];

bool taken[1000005];
bool used[1000005];

int main() {
    ios_base::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    for (int i = 0; i <= 1000000; ++i) {
        df[i].reserve(10);
    }
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (i != j) {
                int c = abs(v[i] - v[j]);
                if ((int) df[c].size() < 2 * (k + 1)) {
                    df[c].PB(v[i]);
                    df[c].PB(v[j]);
                }
            }
        }
    }
    for (int m = 1; m <= 1000001; ++m) {
        vector<int> cused;
        int res = 0;
        for (int d = 0; d <= 1000000; d += m) {
            if ((int) df[d].size() >= 2 * (k + 1)) {
                res = k + 1;
                break;
            }
            FORE (it, df[d]) {
                if (used[*it]) {
                    continue;
                }
                int a = *it % m;
                if (taken[a]) {
                    ++res;
                } else {
                    taken[a] = true;
                }
                used[*it] = true;
                cused.PB(*it);
            }
            if (res > k) {
                break;
            }
        }
        if (res <= k) {
            cout << m << endl;
            return 0;
        }
        FORE (it, cused) {
            used[*it] = false;
            taken[*it % m] = false;
        }
    }
}


#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <cmath>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mran mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define popf pop_front()
#define popb pop_back()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define forr(x,arr) for(auto& x:arr)
#define sz(x) (x.size())
#define mod 1000000007
#define INF 1000000000000000010
#define vi vector<int>
#define vlli vector<lli>

#define endl "\n"

template<class my>
my aabs (const my& a)   { return (a > 0)  ? a : -a;         }
lli gcd(lli a, lli b)   { return (b == 0) ? a : gcd(b,a%b); }
lli LSOne(lli k)        { return (k&(-k));                  }

inline int inv(int o) {
  int b = mod, u = 0, v = 1, t, a=o;
  while (a) {
    t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  if (u < 0) u += mod;
  return u;
}
inline int add(const int &a, const int &b) { return a + b >= mod ? a + b - mod : a + b; }
inline int sub(const int &a, const int &b) { return a - b < 0 ? a - b + mod : a - b; }
inline int mul(const int &a, const int &b) { return int(a * 1ll * b % mod); }
inline int _div(const int &a, const int &b) { return mul(a, inv(b)); }
inline int pow(int a, int b) {
    int ans = 1;
    while (b) {
        if (b & 1) ans = mul(ans, a);
        a = mul(a, a);
        b >>= 1;
    }
    return ans;
}

vi diff[1000005];
bool taken[1000005];
bool used[1000005];

void solve()
{
    int n, k, temp;
    cin>>n>>k;
    vi arr(n+5);
    fol(i,0,n) cin>>arr[i];
    if((n-1)<=k) {cout<<1<<endl; return;}
    fol(i,0,n)
    {
        fol(j,i+1,n)
        {
            temp=aabs(arr[i]-arr[j]);
            if(diff[temp].size()<=2*k)
            {
                diff[temp].pb(arr[i]);
                diff[temp].pb(arr[j]);
            }
        }
    }
    fol(m,2,1000002)
    {
        vector<int> cused;
        int res = 0;
        for (int d = 0; d <= 1000000; d += m) {
            if ((int) diff[d].size() >= 2 * (k + 1)) {
                res = k + 1;
                break;
            }
            forr(x,diff[d]) {
                if (used[x]) {
                    continue;
                }
                int a = x % m;
                if (taken[a]) {
                    ++res;
                } else {
                    taken[a] = true;
                }
                used[x] = true;
                cused.pb(x);
            }
            if (res > k) {
                break;
            }
        }
        if (res <= k) {
            cout << m << endl;
            return ;
        }
        forr (it, cused) {
            used[it] = false;
            taken[it % m] = false;
        }
    }
}

int main()
{
    fastio mran
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}