#include <iostream>
#include <iomanip>
#include <string>
#include <exception>
#include <fstream>
#include <sstream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <thread>
#include <atomic>
#include <mutex>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstdarg>
#include <cctype>
#include <cstring>
using namespace std;
/**************************/
typedef long long ll;

int main() {
    string s, res, *n;
    int am;
    cin >> s >> am;
    n = new string[am];
    cin >> n[0];
    res = n[0];
    for (int i = 1; i < am; i++) {
        cin >> n[i];
        if (res > n[i]) res = n[i];
    }
    if (res.substr(0, s.length()) != s)
        cout << s;
    else
        cout << res;
    delete[] n;
	return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <exception>
#include <fstream>
#include <sstream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <thread>
#include <atomic>
#include <mutex>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstdarg>
#include <cctype>
#include <cstring>
using namespace std;
/**************************/
typedef long long ll;

int main() {
    string s, res, *n;
    int am;
    cin >> s >> am;
    n = new string[am];
    cin >> n[0];
    res = n[0];
    for (int i = 1; i < am; i++) {
        cin >> n[i];
        if (res > n[i] && n[i] >= s) res = n[i];
    }
    if (res.substr(0, s.length()) != s)
        cout << s << endl;
    else
        cout << res << endl;
    delete[] n;
	return 0;
}


#include <iostream>

using namespace std;

int main(){

    int n , t = 0;
    string s;
    cin >> s >> n;
    string s1[n];

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

    bool flag = true;
    for(int i = 0 ; i < n ; i++){
             flag = true;
        for(int j = 0 ; j < s.size(); j++){
            if(s[j] == s1[i][j]) continue;
            else{
                flag = false;
                break;
            }
        }
        if(flag)
            if(s1[i] <= s1[t]) t = i;
    }

    cout << (flag || t != 0 ? s1[t] : s);

return 0;

}


#include <iostream>

using namespace std;

int main(){

    int n , t = 0;
    string s;
    cin >> s >> n;
    string s1[n];

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

    for(int i = 0 ; i < n ; i++){
            bool flag = true;
        for(int j = 0 ; j < s.size(); j++){
            if(s[j] == s1[i][j]) continue;
            else{
                flag = false;
                break;
            }
        }
        if(flag)
            if(s1[i] < s1[t]) t = i;
    }

    cout << (t !=0 ? s1[t] : s);

return 0;

}


#include <iostream>

using namespace std;

int main(){

    int n , t = 0;
    string s;
    cin >> s >> n;
    string s1[n];

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

    bool flag = true;
    for(int i = 0 ; i < n ; i++){
             flag = true;
        for(int j = 0 ; j < s.size(); j++){
            if(s[j] == s1[i][j]) continue;
            else{
                flag = false;
                break;
            }
        }
        if(flag)
            if(s1[i] <= s1[t]) t = i;
    }

    cout << (flag ? s1[t] : s);

return 0;

}


#include <iostream>
#include <fstream>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define fi "A.inp" //div2-49
#define fo "A.out"
#define maxi 2147483647

using namespace std;

int n,k,m,dai,dem,vt,ck,max1,min1,kq,tong,dd;
int d[333];
char s[111],s1[111][111];

int check(int z)
{
    int i,j;

    if(strlen(s1[z])<dai)
        return 0;

    for(i=0;i<dai;i++)
    {
        if(s[i]!=s1[z][i])
           return 0;
    }

    return 1;
}

void sx()
{
    int i,j,k,tg,ds;

    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(strlen(s1[d[i]])>strlen(s1[d[j]]))
                ds=strlen(s1[d[i]]);
            else
                ds=strlen(s1[d[j]]);

            for(k=0;k<ds;k++)
            {
                if(s1[d[i]][k]<s1[d[j]][k])
                    break;

                if(s1[d[i]][k]>s1[d[j]][k])
                {
                    tg=d[i];
                    d[i]=d[j];
                    d[j]=tg;
                    break;
                }
            }
        }
    }
}

void sol()
{
	int i,j,k;

	sx();

    dai=strlen(s);

    for(i=0;i<n;i++)
        if(check(d[i])==1)
        {
            cout<<s1[d[i]]<<endl;
            return;
        }

    cout<<s<<endl;
}

int main()
{
	int i,j;

//	freopen(fi,"r",stdin);
//	freopen(fo,"w",stdout);

	while(cin>>s>>n)
	{
        for(i=0;i<n;i++)
        {
            cin>>s1[i];
            d[i]=i;
        }
		sol();
	}

	return 0;
}


#include <iostream>
#include <fstream>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define fi "A.inp" //div2-49
#define fo "A.out"
#define maxi 2147483647

using namespace std;

int n,k,m,dai,dem,vt,ck,max1,min1,kq,tong,dd;
int d[333];
char s[111],s1[111][111];

int check(char z[])
{
    int i,j;

    for(i=0;i<dai;i++)
    {
        if(s[i]!=z[i])
           return 0;
    }

    return 1;
}

void sol()
{
	int i,j,k,ds;

	dai=strlen(s);
	min1=maxi;
    for(i=0;i<n;i++)
    {
        if(check(s1[i])==1)
        {
            if(min1>strlen(s1[i]))
            {
                min1=strlen(s1[i]);
                kq=i;
            }
        }
    }

    if(min1==maxi)
        cout<<s<<endl;
    else
        cout<<s1[kq]<<endl;
}

int main()
{
	int i,j;

//	freopen(fi,"r",stdin);
//	freopen(fo,"w",stdout);

	while(cin>>s>>n)
	{
        for(i=0;i<n;i++)
        {
            cin>>s1[i];
        }
		sol();
	}

	return 0;
}


#include <iostream>
#include <fstream>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define fi "A.inp" //div2-49
#define fo "A.out"
#define maxi 2147483647

using namespace std;

int n,k,m,dai,dem,vt,ck,max1,min1,kq,tong,dd;
int d[333];
char s[111],s1[111][111];

int check(char z[])
{
    int i,j;

    if(strlen(z)<dai)
        return 0;

    for(i=0;i<dai;i++)
    {
        if(s[i]!=z[i])
           return 0;
    }

    return 1;
}

void sol()
{
	int i,j,k,ds;

	dai=strlen(s);
	min1=maxi;
    for(i=0;i<n;i++)
    {
        if(check(s1[i])==1)
        {
            if(min1>strlen(s1[i]))
            {
                min1=strlen(s1[i]);
                kq=i;
            }
        }
    }

    if(min1==maxi)
        cout<<s<<endl;
    else
        cout<<s1[kq]<<endl;
}

int main()
{
	int i,j;

//	freopen(fi,"r",stdin);
//	freopen(fo,"w",stdout);

	while(cin>>s>>n)
	{
        for(i=0;i<n;i++)
        {
            cin>>s1[i];
        }
		sol();
	}

	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
string s,a[101];
int n,i;
bool pd(const string &a,const string &b)
{
	if(a.length()!=b.length()) return a.length()<b.length();
	for(int i=0; i<a.length(); i++)
	{
		if(a[i]!=b[i]) return a[i]<b[i];
	}
}
int main()
{
	cin>>s;
	cin>>n;
	for(i=1; i<=n; i++) cin>>a[i];
	sort(a+1,a+n+1,pd);
	for(i=1; i<=n; i++)
	{
		int k=a[i].find(s);
		if(k==0) break;
	}
	if(i<=n) cout<<a[i]<<endl;
	else cout<<s<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<string>v;
int main()
{
	string s;
	cin>>s;
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		string t;
		cin>>t;
		if(t.substr(0,s.size())==s)
			v.push_back(t);
	}
	if(v.size()==0)
		cout<<s;
	else
	{
		sort(v.begin(),v.end());
		cout<<v[0]<<endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int n;string s,str[101];
int main()
{
    cin>>s>>n;
    for(int i=1;i<=n;i++)cin>>str[i];
    sort(str+1,str+n+1);
    for(int i=1;i<=n;i++)
        if(!str[i].find(s)){cout<<str[i]<<endl;return 0;}
    cout<<s<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s;
int n;
string t[1000];
int main()
{
	cin>>s>>n;
	for(int i=1; i<=n; i++)
	  cin>>t[i];
	sort(t+1,t+n+1);
    for(int i=1; i<=n; i++)
    {
		int loc = t[i].find(s);
		if( loc==0 )
	      {cout<<t[i]<<endl; return 0;}
	}
	cout<<s<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    string a,b,c;
    cin>>a;
    c=a;
    int n,p=1;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>b;
        int k=1;
        for(int j=0;j<a.size();j++)
            if(a[j]!=b[j]) k=0;
        if(k)
        {
            if(p){c=b;p=0;}
            else
            {
                int kk=0;
                for(int j=0;j<min(c.size(),b.size());j++)
                {
                    if(c[j]>b[j]){c=b;kk=1;break;}
                    if(c[j]<b[j]){kk=1;break;}
                }
                if(kk==0&&c.size()>b.size()) c=b;
            }
        }
    }
    cout<<c;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s;
int n;
string st[110];
set<string> se;
set<string>::iterator it;
bool k;
int main() {
    cin>>s;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>st[i];

    for(int j=1;j<=n;j++) {
        k=false;
        for(int i=0;i<s.size();i++)
            if(s[i]!=st[j][i]) {
                k=true;break;
            }

        if(!k) se.insert(st[j]);
    }

    if(se.empty()) {
        cout<<s;
        exit(0);
    }

    it=se.begin();
    cout<<*it;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s;
string str_n[105];
set<string> str_pd;
set<string>::iterator ans;
bool pd;
int main()
{
	int n;
    cin>>s;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>str_n[i];
    for(int j=1;j<=n;j++)
	{
        pd=false;
        for(int i=0;i<s.size();i++)
            if(s[i]!=str_n[j][i])
			{
                pd=true;
				break;
            }
        if(!pd)
			str_pd.insert(str_n[j]);
    }
    if(str_pd.empty())
	 {
        cout<<s;
        exit(0);
    }
    ans=str_pd.begin();
    cout<<*ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<string>s;
int main(){
	string a;
	cin>>a;
	int n;cin>>n;
	for(int i=1;i<=n;i++){
		string b;cin>>b;
		s.push_back(b);
	}
	sort(s.begin(),s.end());
	int len=a.length();
	char x='z';int oj=-1;
	for(int i=0;i<n;i++){
		int temp=0;
		for(int k=0;k<len;k++){
			if(s[i][k]!=a[k]){
				break;
			}
			else{
				temp++;
			}
		}
		if(temp==len){
			if(s[i][len]<x){
				x=s[i][len];
				oj=i;
			}
		}
	}
	if(oj==-1){
		cout<<a<<endl;
	}
	else cout<<s[oj];
	return 0;
}


#include<iostream>
#include<string>
using namespace std;
string s,a[101];
int n;
int main()
{
	cin>>s;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n-1;i++)
	for(int j=i+1;j<=n;j++)
	if(a[i]>a[j])
	{
	a[0]=a[i];a[i]=a[j];a[j]=a[0];
	}
	for(int i=1;i<=n;i++)
	if(a[i].find(s)==0)
	{
	cout<<a[i];
	return 0;
	}
	cout<<s;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<string>s;
int main(){
	string a;
	cin>>a;
	int n;cin>>n;
	for(int i=1;i<=n;i++){
		string b;cin>>b;
		s.push_back(b);
	}
	int len=a.length();
	char x='z';int oj=-1;
	for(int i=0;i<n;i++){
		int temp=0;
		for(int k=0;k<len;k++){
			if(s[i][k]!=a[k]){
				break;
			}
			else{
				temp++;
			}
		}
		if(temp==len){
			if(s[i][len]<=x){
				x=s[i][len];
				oj=i;
			}
		}
	}
	if(oj==-1){
		cout<<a<<endl;
	}
	else cout<<s[oj];
	return 0;
}


#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main(){
    string s;
    cin>>s;
    int n;
    string mins="zzzzzzzzzz";
    cin>>n;
    string a;
    int lens=s.length();
    bool flag=0;
    for(int i=0;i<n;i++){
        cin>>a;
        int lena=a.length();
        if(lena<lens){
            continue;
        }
        for(int i=0;i<lens;i++){
            if(s[i]!=a[i]){
                continue;
            }
        }
        flag=1;
        if(a<mins) mins=a;
    }
    if(!flag){
        cout<<s;
        return 0;
    }
    cout<<mins;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    string c;
    string ans="";
    int n;
    cin>>s>>n;
    for(int i=0;i<n;i++){
        bool mark=true;
        cin>>c;
        for(int j=0;j<s.size();j++){
        	if(s[j]!=c[j]){
        		mark=false;
			}
		}
        if(mark){
            if(ans==""||ans>c)
            ans=c;
        }
    }
    if(ans==""){
    	cout<<s<<endl;
	}else{
		cout<<ans<<endl;
	}
    return 0;
 }


#include<bits/stdc++.h>
using namespace std;
string s,x,ans="|";
int n;
int main()
{
	cin>>s>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		if(x.find(s)==0)if(x<ans)ans=x;
	}
	if(ans=="|")cout<<s;
	else cout<<ans;
	return 0;
}


#include<map>
#include<list>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int la,lb,lc,n;
char a[10001],b[10001],c[10001];
bool x;
void ll(){
    if(!x){//第一次有解直接赋上就可以
        x=true;
        for(int i=1;i<=la;i++)
            c[i]=a[i];
            return;
    }
    if(strcmp(a+1,c+1)<0){//如果字典序更小
        memset(c,0,sizeof(c));//忘记这个被坑数次否则请看样例1的输出
        for(int i=1;i<=la;i++)//改变c
        c[i]=a[i];
    }
}
void gg(){
    bool y=true;
    memset(a,0,sizeof(a));
    scanf("%s",a+1);
    la=strlen(a+1);
    if(la<lb) return;//直接不够长，根本不可能匹配
    for(int i=1;i<lb;i++){
        if(a[i]!=b[i]){//无法匹配
            y=false;
            break;
        }
        if(a[i]>c[i]){//最优化剪枝，a的字典序一定大于c
            y=false;
            break;
        }
    }
    if(y) ll();//改变c
}
int main(){
    scanf("%s",b+1);
    lb=strlen(b+1);//求b的长度，下同
    for(int i=1;i<=lb;i++)//如果到最后都没有变化就是无解，直接输出b（相当于）
        c[i]=b[i];
    lc=lb;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        gg();
    printf("%s",c+1);//输出c字符串
    return ~~(0-0);
}


#include<bits/stdc++.h>
using namespace std;
string s;
int n;
string st[110];
set<string> se;
set<string>::iterator it;
bool k;
int main() {
    cin>>s;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>st[i];
    //开始检查是否满足条件
    for(int j=1;j<=n;j++) {
        k=false;
        for(int i=0;i<s.size();i++)
            if(s[i]!=st[j][i]) {
                k=true;break;
            }
        //若满足条件则添加到set中
        if(!k) se.insert(st[j]);
    }
    //如果set中没有任何内容，就代表着没有符合条件的
    if(se.empty()) {
        cout<<s;
        exit(0);
    }
    //如果有，那么第一个就是答案（自动按照字典序排序）
    it=se.begin();
    cout<<*it;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
set<string> b;
set<string>::iterator f;
int main()
{
	char a[101],d[101];
	int c;
	cin>>a>>c;
	for(int e=0;e<c;e++)
	{
		cin>>d;
		char g[101];
		if(strstr(d,a)==d)
		{
			b.insert(d);
		}
	}
	f=b.begin();
	if(b.empty())
	{
		cout<<a;
	}
	else
	{
		cout<<*f;
	}
	return 0;
}


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


#include<bits/stdc++.h>
using namespace std;
string s,ans,t;
bool ok=1;
int main()
{
	int n;
	cin>>s;
	ans=s;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>t;
		if(s==t.substr(0,s.size()))
		{
			if(ok)
			{
				ans=t;
				ok=0;
			}
			else ans=min(ans,t);
		}
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int cant;
    string pref;
    cin>>pref>>cant;
    string palabras[cant];
    for(int i = 0; i < cant;i++){
        cin>>palabras[i];
    }
    sort(palabras,palabras+cant);
    for(int i = 0; i < cant;i++){
        string aux = palabras[i];
        bool flag = true;
        for(int j = 0; j < pref.length();j++){
            //cout<<pref[j]<<" "<<aux[j]<<endl;
            if(pref[j] != aux[j]){
                flag = false;
                break;
            }
        }
        if(flag){
            cout<<palabras[i]<<endl;
            return 0;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int cant;
    string pref;
    cin>>pref>>cant;
    string palabras[cant];
    for(int i = 0; i < cant;i++){
        cin>>palabras[i];
    }
    sort(palabras,palabras+cant);
    for(int i = 0; i < cant;i++){
        string aux = palabras[i];
        bool flag = true;
        for(int j = 0; j < pref.length();j++){
            //cout<<pref[j]<<" "<<aux[j]<<endl;
            if(pref[j] != aux[j]){
                flag = false;
                break;
            }
        }
        if(flag){
            cout<<palabras[i]<<endl;
            return 0;
        }
    }
    cout<<pref<<endl;
    return 0;
}


fun main (args:Array<String>){
    var line1 = readLine()!!.split(" ")
    var n = line1[0].toInt()
    var m = line1[1].toInt()
    var line2 = readLine()!!.split(" ")
    var arr = Array(n){0}
    var arrs = Array(n){0}
    var temp = 0
    var counterM = 0

    for(i in 0..n-1){
        arr[i] = line2[i].toInt()
    }

    for(i in arr){
        if(i < 0){
            temp += i * -1
            arrs[counterM] = i * -1
            counterM++
        }
    }

    if(counterM > m){
        temp = 0
        sort(arrs,n)
        var i = 0
        while(i < m){
            temp += arrs[i]
            i++
        }
    }

    println(temp)
}

fun sort (arr:Array<Int>, sz:Int){
    var temp = 0
    var i = 0
    while (i < arr.size){
        if(i != arr.size-2){
            if(arr[i] < arr[i+1]){
                temp = arr[i]
                arr[i] = arr[i+1]
                arr[i+1] = temp
                i = -1
            }
        }else{
            break
        }
        i++
    }
}


fun main(args: Array<String>) {
    print(bobsTvSale())

}

fun bobsTvSale(): Int {
    var savedMoney = 0
    var i = 0
    val s = readLine()
    val test: String? = s?.substringAfter(' ')
    val maxAmount = Integer.parseInt(test)
    val list = readLine()?.split(" ")?.sortedWith(compareBy { Integer.parseInt(it) })
    while (i < maxAmount) {
        val currentNum = Integer.parseInt(list?.get(i))
        savedMoney += if (currentNum < 0) {
            Math.abs(currentNum)
        } else {
            currentNum
        }
        i++
    }
    return savedMoney
}


fun main(args: Array<String>) {
    print(bobsTvSale())

}

fun bobsTvSale(): Int {
    var savedMoney = 0
    var i = 0
    val s = readLine()
    val test: String? = s?.substringAfter(' ')
    val maxAmount = Integer.parseInt(test)
    val list = readLine()?.split(" ")?.sortedWith(compareBy { Integer.parseInt(it) })
    val size = list?.size
    var currentNum = Integer.parseInt(list?.get(0))
    while (currentNum <=0) {
        if (i >= maxAmount){
            return savedMoney
        }
        savedMoney += Math.abs(currentNum)
        i++
        if(i<size!!)
        currentNum = Integer.parseInt(list.get(i))
    }
    return savedMoney
}


fun main(args: Array<String>) {
    print(bobsTvSale())

}

fun bobsTvSale(): Int {
    var savedMoney = 0
    var i = 0
    val s = readLine()
    val test: String? = s?.substringAfter(' ')
    val maxAmount = Integer.parseInt(test)
    val list = readLine()?.split(" ")?.sortedWith(compareBy { Integer.parseInt(it) })
    var currentNum = Integer.parseInt(list?.get(0))
    while (currentNum <=0) {
        if (i >= maxAmount){
            return savedMoney
        }
        savedMoney += Math.abs(currentNum)
        i++
        currentNum = Integer.parseInt(list?.get(i))
    }
    return savedMoney
}


fun main(args: Array<String>) {
    print(bobsTvSale())

}

fun bobsTvSale():Int{
    var savedMoney = 0
    var i = 0
    val s = readLine()
    val test: String? = s?.substringAfter(' ')
    val maxAmount = Integer.parseInt(test)
    val list = readLine()?.split(" ")?.sortedWith(compareBy { Integer.parseInt(it) })
    while (i < maxAmount) {
        savedMoney += Math.abs(Integer.parseInt(list?.get(i)))
        i++
    }
    return savedMoney
}


fun main(args: Array<String>) {
    print(bobsTvSale())

}

fun bobsTvSale(): Int {
    var savedMoney = 0
    var i = 0
    val s = readLine()
    val test: String? = s?.substringAfter(' ')
    val maxAmount = Integer.parseInt(test)
    val list = readLine()?.split(" ")?.sortedWith(compareBy { Integer.parseInt(it) })
    var currentNum = Integer.parseInt(list?.get(0))
    while (currentNum <=0) {
        //currentNum = Integer.parseInt(list?.get(i))
        savedMoney += Math.abs(currentNum)
        if (i >= maxAmount){
            return savedMoney
        }
        i++
        currentNum = Integer.parseInt(list?.get(i))
    }
    return savedMoney
}


import java.util.*

fun main() {

    var (n, m) = readLine()!!.split(" ").map { it.toInt() }
    var list = readLine()!!.split(" ").map { it.toInt() }

    Collections.sort(list)
    var ans = 0
    for (i in 0..m - 1) {
        if (list[i] < 0) {
            ans += list[i]
        }
    }
    println(Math.abs(ans))

}


import java.util.*

fun main() {

    var (n, m) = readLine()!!.split(" ").map { it.toInt() }
    var list = readLine()!!.split(" ").map { it.toInt() }

    Collections.sort(list)
    var ans = 0
    for (i in 0..m-1){
        ans+=list[i]
    }
    println(Math.abs(ans))

}


import java.util.*

fun main() {

    var (n, m) = readLine()!!.split(" ").map { it.toInt() }
    var list = readLine()!!.split(" ").map { it.toInt() }

    var ans = 0
    for (i in 0..m - 1) {
        if (list[i] < 0) {
            ans += list[i]
        }
    }
    println(Math.abs(ans))

}


import java.util.*

fun main() {

    var (n, m) = readLine()!!.split(" ").map { it.toInt() }
    var list = readLine()!!.split(" ").map { it.toInt() }

    var ans = 0
    for (i in 0..n-1) {
        if (list[i] < 0) {
            ans += list[i]
        }
    }
    println(Math.abs(ans))

}


import java.io.BufferedReader
import java.lang.Math.abs
import kotlin.system.measureTimeMillis

fun solve(input: BufferedReader) {
    val (n, m) = input.readLine().split(" ").map {it.toInt()}
//    val a = input.readLine().split(" ").zip(0 until n).map {p -> p.second + 1 - p.first.toInt()}.sorted()
    val a = input.readLine().split(" ").map {it.toInt()}.sorted()
    var sum = 0
    for (i in 0 until m)
        if (a[i] < 0)
            sum -= a[i]
    println(sum)
}

fun main(args: Array<String>) {
    System.err.println("time = ${measureTimeMillis {
        solve(System.`in`.bufferedReader())
//        solve(File("a.out").`bufferedReader())
    }}ms")
}


fun main(args: Array<String>){
	var inp = readLine()!!.split(' ');
	var m = inp[0].toInt();
	var n = inp[1].toInt();
	inp = readLine()!!.split(' ');
	var arr = IntArray(m);
	for(i in 0..m - 1){
		arr[i] = inp[i].toInt();
	}
	arr.sort();
	var ans = 0;
	for(i in 0..n-1){
		if(arr[i] < 0){
			ans += arr[i];
		}else{
			break;
		}
	}
	println(ans * -1);
}
/*
 variable.toInt();
 println("ln");
var a = readLine()?.split(" ");
 var a = readLine()!!.split(" ");
 var (a, b) = readLine()!!.split(' ')
 return String.format("%02d:%02d:%02d", hour, minute, second)
 val zeros = IntArray(3) // первый способ
val zeros = intArrayOf(0, 0, 0) // второй способ при помощи фабричного метода
 al array = arrayOfNulls(3) // [null, null, null]
 var arr2 = arrayOfNulls<String>(2)
arr2.set(0, "1")
arr2.set(1, "2")
 // много кода
if (i >= 0 && i <= 10)
    println(i)

// меньше кода
if (i in 0..10)
    println(i)
 for(i in 1..5){
    println(i)
}
 for(cat in cats){
    println("Кот $cat")
}

Циклы for, while, do-while, forEach, repeat()
for
Вложенные циклы for
forEach
repeat()
while
do-while
for
Цикл for в Kotlin имеет другой синтаксис. Стандартный вариант, когда нужно пробежаться по заданному числу элементов, описывается следующим образом.

for(i in 1..5){
    println(i)
}
Оператор in и его брат !in проверяют вхождение или отсутствие вхождения в диапазон.

В выражении 1..5 мы указываем диапазон от 1 до 5 (пять входит в диапазон). Переменная последовательно примет значение

1
2
3
4
5
Диапазон можно заменить переменной.

val range = 1..5
for(i in range){
    println("Элемент $i")
}
Вместо диапазона можно указать массив.
val cats = arrayListOf<String>()
cats.add("Мурзик")
cats.add("Васька")
cats.add("Барсик")

for(cat in cats){
    println("Кот $cat")
}
Этот же пример можно переписать, используя индекс:

for (index in cats.indices){
    println("Кот ${cats[index]}")
}
 repeat(3){
    println("Васька! Иди жрать!")
}
 for(i in 10 downTo 1 step 2){
    print("$i ")
}
Проверим, является ли символ не цифрой.
fun isNotDigit(c: Char) = c !in '0'..'9'
 val numbers: IntArray = intArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9)
 numbers.sort()
 cats.sortWith(Comparator { c1: Cat, c2: Cat -> c1.age - c2.age })
 fun maxNum(a: Int, b: Int): Int {
    var max = if (a > b) {
        println("The value of a is $a");
        a
    } else {
        println("The value of b is $b")
        b
    }
    return max;
}
 */


fun main(args: Array<String>){
	var inp = readLine()!!.split(' ');
	var m = inp[0].toInt();
	var n = inp[1].toInt();
	inp = readLine()!!.split(' ');
	var arr = IntArray(m);
	for(i in 0..m - 1){
		arr[i] = inp[i].toInt();
	}
	arr.sort();
	var ans = 0;
	for(i in 0..n){
		if(arr[i] < 0){
			ans += arr[i];
		}else{
			break;
		}
	}
	println(ans * -1);
}


//sale:
#include<iostream>
#include<algorithm>
#include<cmath>
#include<stdlib.h>
#include<vector>
using namespace std;
int main(){
    int n, m, price; cin >> n >> m;
    vector<int> v;
    while (n--){
        cin >> price;
        v.push_back(price);
    }
    sort(v.begin(), v.end());
    price = 0;
    for (int i = 0; i < m; i++){
        if (v[i] < 0) price -= v[i];
    }
    cout << price << endl;
    return 0;
}


//sale:
#include<iostream>
#include<algorithm>
#include<cmath>
#include<stdlib.h>
#include<vector>
using namespace std;
int main(){
    int n, m,price; cin >> n >> m;
    vector<int> v;
    while (n--){
        cin >> price;
        v.push_back(price);}
    sort(v.begin(), v.end());
    price = 0;
    for (int i = 0; i < m; i++){
        price -= v[i];
    }
    cout << price << endl;
    return 0;
}


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

int n, m, a[110];

int main()
{
	cin >> n >> m;
	for(int i = 0; i < n; ++ i)
		cin >> a[i];
	sort(a, a + n);
	int ans = 0;
	for(int i = 0; i < m; ++ i)
		if(a[i] < 0)
			ans += a[i];
	cout << abs(ans) << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int i=a;i<b;i++)
#define mp make_pair
#define pb push_back
#define mod 1000000007

int t,n,m,lis[111];

int main( ){
    //freopen("input.txt","r",stdin);
    ios::sync_with_stdio(0);
    cin>>n>>m;
    For(i,0,n) cin>>lis[i];
    sort(lis,lis+n);
    int ans=0;
    For(i,0,m) if(lis[i]<0) ans-=lis[i]; else break;
    cout<<ans;
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
#define l int
#define Mx 1001
#define rep(i,a,n) for(int i = a ; i<=n ; ++i)
l sets[Mx] = {0} ;
l main()
{
    l n , sum = 0 , m ;
    cin>>n>>m ;
    rep(i,0,n-1)
    cin>>sets[i];
    sort(sets,sets+n);
    rep(i,0,m-1){
    if(sets[i]<=0)
    sum+=abs(sets[i]);
    }
    cout<<sum<<endl;
    return 0 ;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef unsigned long long ull;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define maxn int(2e6 + 12)
#define maxb int(2e6 + 12)
#define inf int(1e9 + 7)
#define linf ll(1e18 + 12)
#define eps 1e-7
#define mp make_pair
#define pb push_back
#define fn "a"
#define f first
#define s second

int n, a[200], m;

int main()
{
	#ifdef LOCAL
		freopen(fn".in", "r", stdin);
		freopen(fn".out", "w", stdout);
	#endif
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%d", a + i);
	sort(a, a + n);
	int ans = 0;
	for (int i = 0; i < n && a[i] < 0 && i < m; i++)
		ans -= a[i];
	printf("%d", ans);
}


#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <cassert>
#include <cstring>
#include <sstream>
#include <ctime>
#include <stdexcept>
//#include <unordered_map>
//#include <unordered_set>

using namespace std;

#ifdef MY
#define assert2 assert
#else
#define assert2
#endif // MY

#define input_file(s) assert(freopen(s, "r", stdin))
#define output_file(s) assert(freopen(s, "w", stdout))
#define stderr_file(s) assert(freopen(s, "w", stderr))

#define TASK_FILE_NAME "veryhard"

#define ALL(a) (a).begin(), (a).end()
#define FORAB(i, a, b) for (int i = a; i < b; ++i)
#define PRINTVAR(x) //cerr << #x" = " << x << "\n";

typedef unsigned uint;
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> ipair;

const double PI = 3.14159265358979323846;
const double SQRT2 = 1.41421356237;
const double EPS = 1e-9;

const float SQRT2F = (float)SQRT2;

const int INF = 1e9;
const int64 INF64 = 1e18;

template<class T>
const T sqr(const T &x) { return x * x; }

template<class T>
const T &min(const T &a, const T &b, const T &c) { return min(min(a, b), c); }

template<class T>
const T &max(const T &a, const T &b, const T &c) { return max(max(a, b), c); }

inline void yesno(bool y) { cout << (y? "YES\n" : "NO\n"); }
inline void yes_stop(bool y) { if (y) { yesno(1); exit(0); } }
inline void no_stop(bool y) { if (!y) { yesno(0); exit(0); } }

int gcd(int a, int b) { return b ? gcd (b, a % b) : a; }
int64 gcd(int64 a, int64 b) { return b ? gcd (b, a % b) : a; }

int sgn(int x) { return (x > 0) - (x < 0); }

ostream &operator<<(ostream &os, const ipair &ip) {
    return os << "(" << ip.first << "," << ip.second << ")";
}

class IManip {
public:
    virtual void write(ostream &) const {}
};

template<class It>
class ManipRangePrinter : public IManip {
private:
    const It b, e;

public:
    ManipRangePrinter(It _b, It _e): b(_b), e(_e) {}

    void write(ostream &os) const {
        It g = b;
        if (g != e) os << *g;
        for (++g; g != e; ++g) {
            os << " " << *g;
        }
    }

    It begin() {
        return b;
    }

    It end() {
        return e;
    }
};

class indent : public IManip {
private:
    const int c;
public:
    indent(int c): c(c) {}

    void write(ostream &os) const {
        for (int i = 0; i < c; ++i) os << " ";
    }
};

ostream &operator<<(ostream &os, const IManip &man) {
    man.write(os);
    return os;
}

template<class It>
ManipRangePrinter<It> range(It b, It e) { // stream manip
    return ManipRangePrinter<It>(b, e);
}

struct Edge {
    int to, w;

    bool operator<(const Edge &x) const {
        if (to == x.to) return w < x.w;
        return to < x.to;
    }
};

// !GLOB

int main() {
    #ifdef MY
    input_file("input.txt");
    //output_file("output.txt");
    //stderr_file("stderr.txt");
    #else
    //input_file(TASK_FILE_NAME".in");
    //output_file(TASK_FILE_NAME".out");
    //input_file("input.txt");
    //output_file("output.txt");
    #endif

    ios_base::sync_with_stdio(0);

    // !MAIN

    int n, m, a[500];

    cin >> n >> m;

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

    sort(a, a + n);

    int ans = 0;

    for (int i = 0; i < m; ++i) {
        if (a[i] >= 0) break;
        ans += a[i];
    }

    cout << -ans << "\n";

    return 0;
}


#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <bitset>
#include <algorithm>
#include <functional>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <climits>
#include <cstring>
#include <cctype>

using namespace std;

typedef vector<int> vi;
typedef vector<vi > vvi;
typedef pair<int,int> ii;
typedef vector<ii > vii;
typedef vector<vii > vvii;
typedef set<ii > sii;
int mov[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1,};

#define pb push_back
#define mp(a, b) make_pair((a), (b))
#define all(c) (c).begin(),(c).end()
#define PI (acos(-1))
#define EPS 1e-7
#define INF 1000000000
#define MOD 1000000007
// #define CUS_DEBUG

#ifdef CUS_DEBUG
#include "debug.h"
#else
#define debug(a)
#define debug_array(a, n)
#define debug_array2(a, n, m)
#endif

template<typename T>
struct number_iterator : std::iterator<random_access_iterator_tag, T>{
    T v;
    number_iterator(T _v) : v(_v) {}
    operator T&(){return v;}
    T operator *() const {return v;}
};
template <typename T>
struct number_range {
    T b,e;
    number_range(T b, T e):b(b),e(e){}
    number_iterator<T> begin(){return b;}
    number_iterator<T> end(){return e;}
};
template<typename T> number_range<T> range(T e) {return number_range<T>(0, e);}
template<typename T> number_range<T> range(T b, T e) {return number_range<T>(b, e);}

int main()
{
    int n, m;
    cin >> n >> m;
    vi v(n);
    for (auto i: range(n))
        cin >> v[i];
    sort(all(v));
    int total = 0;
    for (auto i: range(m)) {
        if (v[i] < 0)
            total += (-v[i]);
        else
            break;
    }
    cout << total << endl;
    return 0;
}


//by maximumSHOT

#define _USE_MATH_DEFINES

#include <iostream>
#include <cmath>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <time.h>
#include <clocale>
#include <fstream>
#include <conio.h>
#include <random>

using namespace std;

#define forx(i,n) for(int i(0);i < n;i++)
#define vec vector
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()

typedef long L;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef long double LD;
typedef vector<int> vint;
typedef vec<LL> vll;
typedef vector<vint> vvint;
typedef vector<double> vdouble;
typedef vector<vector<double>> vvdouble;
typedef vec<bool> vbool;
typedef vec<vec<bool>> vvbool;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<double,int> pdi;
typedef pair<int,double> pid;
typedef unsigned long long ull;
typedef unsigned int ui;
const int inf = 1000 * 1000 * 1000;
const LL inf64 = LL(inf) * inf;
const LL base  = 1e9+7;
const double pi = acos(-1.0);
inline LL Sqr(LL a){return a*a;}
struct Tripple
{
    int first;
    int second;
    int third;

    void make_tripple(int a,int b,int c)
    {
        first  = a;
        second = b;
        third  = c;
    }
};
bool cmp1(Tripple a,Tripple b)
{
    return a.first < b.first;
}
bool cmp2(Tripple a,Tripple b)
{
    return a.second < b.second;
}
bool cmp3(Tripple a,Tripple b)
{
    return a.third < b.third;
}

// GL begin

// GL end

//Functions begin

//Functions end

bool solve()
{
    ios_base::sync_with_stdio(0);
    ifstream fin("input.txt");
    ofstream fout("output.txt");
    //#define cin fin
    //#define cout fout

    LL n, m, ans = 0;

    cin >> n >> m;

    vec<LL> a;

    for(LL x, i(0);i < n;i++)
    {
        cin >> x;
        if(x < 0) a.push_back(x);
    }

    sort(ALL(a));

    for(int i(0);i < min(m, a.size() * 1ll);i++) ans -= a[i];

    cout << ans << '\n';

    //_getch();
    return true;
}

int main(int argc,char **argv)
{
    //while(solve());
    solve();

    return 0;
}


#define _SOLUTION                    \
                                     \
                                     \
void solve() {                       \
    $I2(int, n, m);                  \
    $Ix(int, a, n);                  \
    seqarr(A, _mapi(a, max(0, -_))); \
    _rsort(A);                       \
    _w( _sum( _take(m, A) ) );       \
}                                    \
                                     \
_END_SOL                             \
//////////////////////////////////////
//
// ====== <<< PREWRITTEN CODE >>> ============================================
//
#pragma comment(linker, "/STACK:32000000")
#define _CRT_SECURE_NO_DEPRECATE
#include <sstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <stdarg.h>
#include <memory.h>
#include <string.h>
#include <assert.h>
#include <type_traits>
#include <limits>
#include <hash_map>
#include <hash_set>
using namespace std;
#define gcc_typename typename
using namespace __gnu_cxx;
#define LL_SPEC "%I64d"
#define ITER_WRITE inline void _write() const { _wstr("["); write_iterable(*this, SepComma()); _wstr("]"); }
#define SEQ_TYPE(x) const x
#define __block(...) do { __VA_ARGS__ } while (0)
struct _DummyType {};
template<typename T>
struct ValueType {
	typedef typename remove_reference<T>::type clean_type;
	typedef typename clean_type::value_type type;
};
#define _wstr(s) printf("%s", s)
#define cmp_a(a) a < other.a
#define cmp_aa(a, b) cmp_a(a) || (a == other.a && b < other.b)
template<typename T>
struct item_type { typedef typename T::value_type type; };
template<typename T>
struct item_type<T*> { typedef T type; };
template<typename T, size_t sz>
struct item_type<T[sz]> { typedef T type; };
template<typename T, size_t sz>
struct item_type<T(&)[sz]> { typedef T type; };
template<typename T>
struct item_type<T*&> { typedef T type; };
template<typename T>
struct item_type<T**> { typedef T type; };
template<typename T>
struct item_type<T**&> { typedef T type; };
template<typename T>
struct _null { inline static T value() { return T(-1); } };
template<typename T>
struct _seq
{
    template<typename F>
    static inline void process(T &t, F f) { t.process(f); }
};
template<typename T>
struct _seq<const T>
{
	template<typename F>
	static inline void process(const T &t, F f) { t.process(f); }
};
template<typename T>
struct _seq<vector<T> >
{
    template<typename F>
    static void process(vector<T> &t, F f)
    {
        for (typename vector<T>::iterator it = t.begin(); it != t.end(); ++it)
            if (!f(*it)) break;
    }
};
template<typename T>
struct _seq<const vector<T> >
{
    template<typename F>
    static void process(const vector<T> &t, F f)
    {
        for (typename vector<T>::const_iterator it = t.begin(); it != t.end(); ++it)
            if (!f(*it)) break;
    }
};
template<>
struct _seq<string>
{
    template<typename F>
    static void process(string &s, F f)
    {
        for (size_t i = 0; i < s.length(); i++)
            if (!f(s[i])) break;
    }
};
template<>
struct _seq<const string>
{
    template<typename F>
    static void process(const string &s, F f)
    {
        for (size_t i = 0; i < s.length(); i++)
            if (!f(s[i])) break;
    }
};
template<typename T, typename F>
inline void _seq_process_c(const T &t, F f)
{
	_seq<const T>::template process<F>(t, f);
}
#define xbreak return false
#define xforeach_(a, v) \
    _seq_process_c(a, [&](const gcc_typename ValueType<decltype(a)>::type &v) -> bool {
#define xforeachi_(a, i, v) \
    { \
    typedef const gcc_typename ValueType<decltype(a)>::type &_T_; \
    int i = -1; \
    _seq_process_c(a, [&](_T_ v) -> bool { ++i; return [&]() -> bool {
#define x_endfe return true; });
#define x_endfei return true; }(); }); }
#define xforeach(a, v, ...)  xforeach_(a, v) __VA_ARGS__; x_endfe
#define xforeachi(a, i, v, ...) xforeachi_(a, i, v) __VA_ARGS__; x_endfei
#define xfor(a, v, ...) xforeach(a, v, __VA_ARGS__)
struct SepComma { inline static void Print() { _wstr(", "); } };
static char __strbuf[1000001];
template<typename T>
struct _io
{
	inline static void read(T &x, int i) { x._read(i); }
	inline static void write(const T &x) { x._write(); }
};
template<>
struct _io<int>
{
	inline static void read(int &x, int i) { scanf("%d", &x); }
	inline static void write(const int &x) { printf("%d", x); }
};
template<>
struct _io<int&>
{
	inline static void read(int &x, int i) { scanf("%d", &x); }
	inline static void write(const int &x) { printf("%d", x); }
};
template<>
struct _io<const int&>
{
	inline static void write(const int &x) { printf("%d", x); }
};
template<>
struct _io<long long>
{
	inline static void read(long long &x, int i) { scanf(LL_SPEC, &x); }
	inline static void write(const long long &x) { printf(LL_SPEC, x); }
};
template<>
struct _io<long long&>
{
	inline static void read(long long &x, int i) { scanf(LL_SPEC, &x); }
	inline static void write(const long long &x) { printf(LL_SPEC, x); }
};
template<>
struct _io<double>
{
	inline static void read(double &x, int i) { scanf("%lf", &x); }
	inline static void write(const double &x) { printf("%.9lf", x); }
};
template<>
struct _io<const double>
{
	inline static void write(const double &x) { printf("%.9lf", x); }
};
template<>
struct _io<double&>
{
	inline static void read(double &x, int i) { scanf("%lf", &x); }
	inline static void write(const double &x) { printf("%.9lf", x); }
};
template<>
struct _io<char>
{
	inline static void read(char &c, int i) { char buf[3]; scanf("%s", buf); c = buf[0]; }
	inline static void write(const char &c) { printf("%c", c); }
};
template<>
struct _io<bool>
{
	inline static void read(bool &b, int i) { int t; scanf("%d", &t); b = t != 0; }
	inline static void write(const bool &b) { printf("%s", b ? "#t" : "#f"); }
};
template<>
struct _io<string>
{
    inline static void read(string &s, int i) { scanf("%s", __strbuf); s = string(__strbuf); }
    inline static void write(const string &s) { printf("%s", s.c_str()); }
};
template<typename T> inline void _w(const T &a) { _io<T>::write(a); }
template<typename T>
struct Idx2
{
    T i, j;
    Idx2(T i, T j) : i(i), j(j) {}
    Idx2() : i(-1), j(-1) {}
    inline void _write() const { _wstr("("); _io<T>::write(i); _wstr(", "); _io<T>::write(j); _wstr(")"); }
    inline void _read(int idx) { _io<T>::read(i, idx); _io<T>::read(j, idx); }
	inline bool operator == (const Idx2<T> &other) const { return i == other.i && j == other.j; }
	inline bool operator < (const Idx2<T> &other) const { return cmp_aa(i, j); }
};
template<typename T>
struct _null<Idx2<T> > { inline static Idx2<T> value() { return Idx2<T>(-1, -1); } };
template<typename T>
struct cmap
{
};
template<typename Y>
struct cmap<Y**>
{
	typedef Idx2<int> key_type;
	inline static void write(Y **a, key_type i, const Y &value) { a[i.i][i.j] = value; }
	inline static Y& read(Y **a, key_type i) { return a[i.i][i.j]; }
};
template<typename Y>
struct cmap<Y**&>
{
	typedef Idx2<int> key_type;
	inline static void write(Y **&a, key_type i, const Y &value) { a[i.i][i.j] = value; }
	inline static Y& read(Y **&a, key_type i) { return a[i.i][i.j]; }
};
template<typename Y, int sz>
struct cmap<Y [sz]>
{
	typedef int key_type;
	inline static void write(Y a[sz], int i, const Y &value) { a[i] = value; }
	inline static Y& read(Y a[sz], int i) { return a[i]; }
};
template<typename Y, int sz>
struct cmap<Y (&)[sz]>
{
	typedef int key_type;
	inline static void write(Y (&a)[sz], int i, const Y &value) { a[i] = value; }
	inline static Y& read(Y (&a)[sz], int i) { return a[i]; }
};
template<typename Y>
struct cmap<Y*>
{
	typedef int key_type;
	inline static void write(Y *a, int i, const Y &value) { a[i] = value; }
	inline static Y& read(Y *a, int i) { return a[i]; }
};
template<typename Y>
struct cmap<Y*&>
{
	typedef int key_type;
	inline static void write(Y *&a, int i, const Y &value) { a[i] = value; }
	inline static Y& read(Y *&a, int i) { return a[i]; }
};
#define $I(type, name) \
	type name; \
	_io<type>::read(name, 0)
#define $I2(type, name1, name2) $I(type, name1); $I(type, name2)
#define _inx(type, name, sz) \
	type *name; \
	name = new type[sz]; \
	for (int __i = 0; __i < sz; __i++) _io<type>::read(name[__i], __i);
#define _tmpx(type, name, sz) \
	type *name; \
	name = new type[sz];
template<typename T, typename sep>
void write_array(const T &a, int n)
{
	typedef typename item_type<T>::type X;
	for (int i = 0; i + 1 < n; i++)
	{
		_io<X>::write(a[i]);
		sep::Print();
	}
	if (n > 0) _io<X>::write(a[n-1]);
}
template<typename T, typename Sep>
void write_iterable(const T &a, Sep sep)
{
	bool first = true;
    typedef typename T::value_type i_type;
	xforeach(a, i,
		if (!first) sep.Print();
		_io<i_type>::write(i);
		first = false;
	)
}
template<typename T>
struct _io<vector<T> >
{
	inline static void read(vector<T> &x, int idx)
    {
        int sz;
        _io<int>::read(sz, 0);
        assert(sz >= 0);
        x.resize(sz);
        for (int i = 0; i < sz; i++) _io<T>::read(x[i], i);
    }
	inline static void write(const vector<T> &x) { _wstr("["); write_array<vector<T>, SepComma>(x, x.size()); _wstr("]"); }
};
#define seqarr(name, a) \
	const auto &name##_tmp = a; \
	$Tx(ValueType<decltype(name##_tmp)>::type, name, xlen(name##_tmp)); \
	xforeachi(name##_tmp, i, x, name[i] = x);
#define _sort(a) if (a.size() > 0) sort(&a[0], &a[0] + a.size())
#define _reverse(a) if (a.size() > 0) reverse(&a[0], &a[0] + a.size())
#define _rsort(a) __block( _sort(a); _reverse(a); )
template<typename T, typename F>
typename T::value_type Fold(const T &a, F f, const typename T::value_type &init_val)
{
	typename T::value_type res = init_val;
	xforeach(a, i, res = f(res, i));
	return res;
}
template<typename T>
struct SumFtr
{
	typedef T res_type;
	inline T operator () (const T &a, const T &b) const { return a + b; }
};
template<typename T>
struct _sum_neutral
{
	static T value() { return T(0); }
};
template<typename T>
typename T::value_type _sum(const T &a)
{
	typedef typename T::value_type X;
	return Fold(a, SumFtr<X>(), _sum_neutral<X>::value());
}
template<typename T>
int xlen(const T &a) { return (int)a.size(); }
template<typename T>
struct key_type { typedef int type; };
template<typename ArrType>
struct ArrWrapper
{
	typedef ArrType base_type;
	ArrType &a;
	int n;
	ArrWrapper(ArrType &a, int n) : a(a), n(n) {}
	typedef typename item_type<ArrType>::type value_type;
	typedef int iterator;
	inline iterator begin() const { return 0; }
	inline iterator end() const { return n; }
	inline int size() const { return n; }
	inline value_type& resolve_iterator(const iterator &it) const
	{
		return cmap<ArrType>::read(a, it);
	}
	inline value_type& operator [] (int i) { return a[i]; }
	void erase(int p)
	{
		assert(p < n);
		for (int i = p + 1; i < n; ++i) a[i-1] = a[i];
		--n;
	}
    template<typename F>
    void process(F f) const
    {
        for (int i = 0; i < n; i++)
            if (!f(a[i])) break;
    }
	ITER_WRITE
};
template<typename T>
struct cmap<ArrWrapper<T> >
{
	typedef typename ArrWrapper<T>::value_type V;
	inline static void write(ArrWrapper<T> &a, int i,
		const V value) { a.a[i] = value; }
	inline static V& read(ArrWrapper<T> &a, int i) { return a.a[i]; }
};
#define _wrap(name, base, n) \
	ArrWrapper<decltype(base)> name(base, n)
#define $Ix(type, name, n) \
	_inx(type, name##_base, n); \
	_wrap(name, name##_base, n)
#define $Tx(type, name, n) \
	_tmpx(type, name##_base, n); \
	_wrap(name, name##_base, n)
template<typename T, typename F, typename S>
struct MapIWrapper
{
	SEQ_TYPE(T) a;
	typedef S value_type;
	F f;
	MapIWrapper(const T &a, F f) : a(a), f(f) {}
	template<typename Ftr>
	inline void process(Ftr ftr) const
	{
		int i = 0;
		xfor(a, x,
			if (!ftr(f(i, x))) xbreak;
			++i;
		);
	}
	inline int size() const { return a.size(); }
	ITER_WRITE
};
template<typename T, typename F>
auto create_mapi(const T &a, F f) -> MapIWrapper<T, F, decltype(f( 0, gcc_typename ValueType<T>::type() ))>
{
	return MapIWrapper<T, F, decltype(f( 0, gcc_typename ValueType<T>::type() ))>(a, f);
}
#define _mapi(a, ...) create_mapi(a, [&](int i, const ValueType<decltype(a)>::type &_) \
	 { return __VA_ARGS__; })
template<
    typename T
>
struct TakeWrapper
{
    SEQ_TYPE(T) a;
    int cnt;
    TakeWrapper(int cnt, const T &a) : cnt(cnt), a(a) { assert(cnt >= 0); }
    typedef typename T::value_type value_type;
    template<typename F>
    inline void process(F f) const
    {
		if (cnt <= 0) return;
        int i = 0;
        xforeach(a, x,
            if (!f(x)) xbreak;
			++i;
			if (i >= cnt) xbreak;
        )
    }
    inline int size() const { return min(cnt, (int)a.size()); }
    typedef _DummyType iterator;
	ITER_WRITE
};
template<typename T>
inline TakeWrapper<T> _take(int cnt, const T &a)
{
    return TakeWrapper<T>(cnt, a);
}
#ifndef ONLINE_JUDGE
#define _open_files(name) freopen(name ".in", "r", stdin); freopen(name ".out", "w", stdout)
#else
#define _open_files(name)
#endif
#define _END_SOL int main() { _open_files("test"); solve(); return 0; }
_SOLUTION


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

int main()
{
  int size1, bag;

  cin >> size1 >> bag;
  int masive[size1];
  for(int i=0;i< size1; i++)
    {
    cin>>masive[i]; }

 for(int i=1;i<size1;i++)
    {
        int temp = masive[i];
        int j=i-1;
        while(temp<masive[j] && j>=0)

        {
            masive[j+1] = masive[j];
            --j;
        }
        masive[j+1]=temp;
    }
  /* for (int i=0; i < size; i++)
     cout << array[i];
*/
  int sum=0;
  for( int i=0;i<bag;i++)
        sum+=masive[i];

     cout << sum;

return 0;
}


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

int main()
{
  int size1, bag;

  cin >> size1 >> bag;
  int masive[size1];
  for(int i=0;i< size1; i++)
    {
    cin>>masive[i]; }

 for(int i=1;i<size1;i++)
	{
		int temp = masive[i];
		int j=i-1;
		while(temp<masive[j] && j>=0)

		{
			masive[j+1] = masive[j];
			--j;
		}
		masive[j+1]=temp;
	}
  /* for (int i=0; i < size; i++)
     cout << array[i];
*/
  int sum=0;
  for( int i=0;i<bag;i++)
        sum+=masive[i];

     cout << sum;

return 0;
}


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

int main()
{
  int size1, bag;

  cin >> size1 >> bag;
  int masive[size1];
  for(int i=0;i< size1; i++)
    {
    cin>>masive[i]; }

 for(int i=1;i<size1;i++)
	{
		int temp = masive[i];
		int j=i-1;
		while(temp<masive[j] && j>=0)

		{
			masive[j+1] = masive[j];
			--j;
		}
		masive[j+1]=temp;
	}
/*   for (int i=0; i < size1; i++)
     cout << masive[i] << "  " ;
*/  int sum=0;
  for( int i=0;i<bag;i++)
        sum+=masive[i];

     cout << sum;

return 0;
}


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

int main()
{
  int size1, bag;

  cin >> size1 >> bag;
  int masive[size1];
  for(int i=0;i< size1; i++)
    {
    cin>>masive[i]; }

 for(int i=1;i<size1;i++)
	{
		int temp = masive[i];
		int j=i-1;
		while(temp<masive[j] && j>=0)

		{
			masive[j+1] = masive[j];
			--j;
		}
		masive[j+1]=temp;
	}
   for (int i=0; i < size1; i++)
     cout << masive[i] << "  " ;
  int sum=0;
  for( int i=0;i<bag;i++)
        sum+=(0 - masive[i]);

     cout << sum;

return 0;
}


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

int main()
{
  int size1, bag;

  cin >> size1 >> bag;
  int masive[size1];
  for(int i=0;i< size1; i++)
    {
    cin>>masive[i]; }

 for(int i=1;i<size1;i++)
	{
		int temp = masive[i];
		int j=i-1;
		while(temp<masive[j] && j>=0)

		{
			masive[j+1] = masive[j];
			--j;
		}
		masive[j+1]=temp;
	}
 /*  for (int i=0; i < size1; i++)
     cout << masive[i] << "  " ;
*/  int sum=0;
    int counter=0;
 while ( counter < bag && masive[counter] < 0)
 {
     sum -= masive[counter];
     counter++;
 }

     cout << sum;

return 0;
}


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

int main()
{
  int size1, bag;

  cin >> size1 >> bag;
  int masive[size1];
  for(int i=0;i< size1; i++)
    {
    cin>>masive[i]; }

 for(int i=1;i<size1;i++)
	{
		int temp = masive[i];
		int j=i-1;
		while(temp<masive[j] && j>=0)

		{
			masive[j+1] = masive[j];
			--j;
		}
		masive[j+1]=temp;
	}
 /*  for (int i=0; i < size1; i++)
     cout << masive[i] << "  " ;
*/  int sum=0;
    int counter=0;
 while ( counter <= bag && masive[counter] < 0)
 {
     sum -= masive[counter];
     counter++;
 }

     cout << sum;

return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt", "rt", stdin);
#endif
    int n, m;
    while (cin >> n >> m) {
        int tv[n];
        for (int i = 0; i < n; i++) {
            cin >> tv[i];
        }
        sort(tv, tv + n);
        int result = 0;
        for (int i = 0; i < m; i++)
            if (tv[i] <= 0)
                result -= tv[i];
        cout << result << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt", "rt", stdin);
#endif
    int n, m;
    while (cin >> n >> m) {
        int tv[n];
        for (int i = 0; i < n; i++) {
            cin >> tv[i];
        }
        sort(tv, tv + n);
        int result = 0;
        for (int i = 0; i < m; i++)
            result-=tv[i];
        cout << result << endl;
    }
    return 0;
}


#include <iostream>
using namespace std;

int main() {
    int n,m,sum=0;
    cin>>n>>m;
    int* a=new int [n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0; i<m; i++)
    {
        for(int j=i+1; j<n; j++)
        {
            if(a[j]<a[i])
            swap(a[j],a[i]);
        }
        sum=sum-a[i];
    }
    cout<<sum<<endl;
    // your code goes here
    return 0;
}


#include <iostream>
using namespace std;

int main() {
    int n,m,sum=0;
    cin>>n>>m;
    int* a=new int [n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0; i<m; i++)
    {
        for(int j=i+1; j<n; j++)
        {
            if(a[j]<a[i])
            swap(a[j],a[i]);
        }
        if(sum-a[i]<sum)
        break;
        else
        sum=sum-a[i];
    }
    cout<<sum<<endl;
    // your code goes here
    return 0;
}


#include <bits/stdc++.h>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
using namespace std; typedef long double ld; template <class _T> inline _T sqr(const _T& x) {return x * x;} template <class _T> inline string tostr(const _T& a) {ostringstream os(""); os << a; return os.str();} const ld PI = 3.1415926535897932384626433832795L; const ld EPS = 5e-12; char TEMPORARY_CHAR; typedef long long ll; typedef unsigned long long ull; typedef set < int > SI; typedef vector < int > VI; typedef vector < vector < int > > VVI; typedef map < string, int > MSI; typedef pair < int, int > PII; const int INF = 1e9; typedef complex<ld> cbase; inline void fft (vector<cbase> &a, bool invert) {int n = (int)a.size(); for (int i = 1, j = 0; i < n; ++i) {int bit = n >> 1; for (; j >= bit; bit >>= 1) j -= bit; j += bit; if (i < j) swap(a[i], a[j]);} for (int len = 2; len <= n; len <<= 1) {ld ang = 2 * PI / len * (invert ? -1 : 1); cbase wlen(cos(ang), sin(ang)); for (int i = 0; i < n; i += len) {cbase w(1); for (int j=0; j < len / 2; ++j) {cbase u = a[i + j], v = a[i + j + len / 2] * w; a[i + j] = u + v; a[i + j + len / 2] = u - v; w *= wlen;}}} if (invert) for (int i = 0; i < n; ++i) a[i] /= n;} inline void input(int &a) {a = 0; while (((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') && (TEMPORARY_CHAR != '-')){} char neg = 0; if (TEMPORARY_CHAR == '-') {neg = 1; TEMPORARY_CHAR = getchar();} while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0') {a = (a << 3) + (a << 1) + TEMPORARY_CHAR - '0'; TEMPORARY_CHAR = getchar();} if (neg) a = -a;} inline void out(ll a) {if (!a) putchar('0'); if (a < 0) {putchar('-'); a = -a;} char s[20]; int i; for(i = 0; a; ++i) {s[i] = '0' + a % 10; a /= 10;} ford(j, i) putchar(s[j]);} inline int nxt() {in(ret); return ret;} struct lnum {vector <int> a; int base; lnum(int num = 0, int base = 1000000000):base(base) {if (!num) a.resize(1); while(num) {a.pb(num % base); num /= base;}} inline int len() const {return a.size();} lnum & operator=(const lnum &l) {if (this != &l) {a = l.a; base = l.base;} return *this;} inline friend lnum operator+(const lnum &l, const lnum &r) {lnum ret(0, l.base); int base = l.base; int ln = l.len(), rn = r.len(); int n = max(ln, rn); ret.a.resize(n); int o = 0; for(int i = 0; i < n; ++i) {int s = o; if (i < ln) s += l.a[i]; if (i < rn) s += r.a[i]; o = s >= base; if (o) s -= base; ret.a[i] = s;} if (o) ret.a.push_back(1); return ret;} inline friend lnum operator-(const lnum &l, const lnum &r) {lnum ret(0, l.base); int base = l.base; int n = l.len(); int rn = r.len(); ret.a.resize(n); int o = 0; for(int i = 0; i < n; ++i) {int s = l.a[i] - o; if (i < rn) s -= r.a[i]; o = s < 0; if (o) s += base; ret.a[i] = s;} if (ret.len() > 1 && !ret.a.back()) ret.a.pop_back(); return ret;} inline friend lnum operator*(const lnum &l, const lnum &r) {lnum ret(0, l.base); int base = l.base; if (l.len() * r.len() > 1000000) {vector<cbase> fa (l.a.begin(), l.a.end()), fb (r.a.begin(), r.a.end()); int n = 1; while (n < max (l.len(), r.len())) n <<= 1; n <<= 1; fa.resize (n), fb.resize (n); fft (fa, false), fft (fb, false); for (int i = 0; i < n; ++i) fa[i] *= fb[i]; fft (fa, true); ret.a.resize(n); for (int i = 0; i < n; ++i) ret.a[i] = int (fa[i].real() + 0.5); int carry = 0; for (int i=0; i < n; ++i) {ret.a[i] += carry; carry = ret.a[i] / base; ret.a[i] %= base;}} else {ret.a.resize(l.len() + r.len()); for (int i = 0; i < l.len(); ++i) for (int j = 0, carry = 0; j < r.len() || carry; ++j) {long long cur = ret.a[i + j] + (ll)l.a[i] * (j < r.len() ? r.a[j] : 0) + carry; ret.a[i + j] = cur % base; carry = cur / base;}} while (ret.len() > 1 && !ret.a.back()) ret.a.pop_back(); return ret;} inline friend lnum operator/(const lnum &l, const int &r) {lnum ret(0, l.base); ret.a.resize(l.len()); int carry = 0; for(int i = l.len() - 1; i >= 0; --i) {long long cur = l.a[i] + (ll)carry * l.base; ret.a[i] = cur / r; carry = cur % r;} while (ret.len() > 1 && ret.a.back() == 0) ret.a.pop_back(); return ret;}  inline friend bool operator<(const lnum &l, const lnum &r) {if (l.len() < r.len()) return true; if (l.len() > r.len()) return false; int n = l.len(); for(int i = n - 1; i >= 0; --i) {if (l.a[i] < r.a[i]) return true; if (l.a[i] > r.a[i]) return false;} return false;} inline friend bool operator>(const lnum &l, const lnum &r) {return r < l;} inline friend bool operator==(const lnum &l, const lnum &r) {if (l.len() != r.len()) return false; int n = l.len(); for(int i = n - 1; i; --i) {if (l.a[i] != r.a[i]) return false;} return true;} inline friend bool operator!=(const lnum &l, const lnum &r) {return !(l == r);} inline void print() {if (base == 1000000000) {printf("%d", a.back()); for(int i = a.size() - 2; i >=0; --i) printf("%09d", a[i]);} else {for(int i = a.size() - 1; i >= 0; --i) printf("%d", a[i]);}}};

int main()
{
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int a[n];
    for(int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    sort(a, a + n);
    int i = 0;
    int sum = 0;
    while(i < m && a[i] < 0)
    {
        sum -= a[i];
        i++;
    }
    cout << sum << endl;
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<deque>
#include<ctype.h>
#include<sstream>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef unsigned long long ull;

#define FOR(i,a,b) for (int i(a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define SORT(v) sort((v).begin(),(v).end())
#define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define CL(a,b) memset(a,b,sizeof(a))
#define pb push_back

int main()
{
    int n,m,answer=0;
    vector<int> v;
    cin>>n>>m;
    REP(i,n)
    {
        int j;
        cin>>j;
        v.pb(j);
    }
    SORT(v);
    REP(i,m)
    {
        if (v[i]>0)
        {
            break;
        }
        answer+=v[i];
    }
    cout<<answer;
}


#include<stdio.h>
#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<deque>
#include<ctype.h>
#include<sstream>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef unsigned long long ull;

#define FOR(i,a,b) for (int i(a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define SORT(v) sort((v).begin(),(v).end())
#define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define CL(a,b) memset(a,b,sizeof(a))
#define pb push_back

int main()
{
    int n,m,answer=0;
    vector<int> v;
    cin>>n>>m;
    REP(i,n)
    {
        int j;
        cin>>j;
        v.pb(j);
    }
    SORT(v);
    REP(i,m)
    {
        if (v[i]>0)
        {
            break;
        }
        answer+=v[i];
    }
    cout<<0-answer;
}


# define M_PI           3.14159265358979323846  /* pi */
#include <cstdio>
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <vector>
#include <unordered_map>
#include <map>
#include <math.h>
#define ff(i,s,n) for(int i=(s);i<(n);i++)
#define fr(i,s,n) for(int i=(n-1);i>=(s);i--)
#define FF(i,s,n) for(int i=(s);i<=(n);i++)
#define Fr(i,s,n) for(int i=(n);i>=(s);i--)
#define mp(a,b) make_pair(a,b)

template<typename T, typename U> inline void swap(T &a, U &b) {
    a = a^b;
    b = a^b;
    a = a^b;
}

inline void swap(int &a, int &b) {
    a = a^b;
    b = a^b;
    a = a^b;
}

inline void smax(int &a, int b) {
    if (b > a)a = b;
}

inline void smin(int &a, int b) {
    if (b < a)a = b;
}

inline int gcd(int a, int b) {
    if (a < b)swap(a, b);
    while (b > 0) {
        a -= a / b*b;
        swap(a, b);
    }
    return a;
}

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<string, string> > vpss;
typedef vector<pair<int, int> > vpii;
typedef unordered_map<int, int> imap;
typedef unordered_map<long long, long long> lmap;

int readint(){
    int x=0;
    int two=1;
    ff(i,0,10){
        char c;cin>>c;
        x+=c*two;
        two*=2;
    }
    return x;
}
int n,m;vi v(0);
int ac=0;
int main() {
    cin>>n>>m;ff(i,0,n){
        int t;
        cin>>t;
        if(t<0)v.push_back(t);
    }
    sort(v.begin(),v.end());
    v.resize(101,0);

    ff(i,0,m){
        ac-=v[i];
    }
    cout<<ac;
}


# define M_PI           3.14159265358979323846  /* pi */
#include <cstdio>
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <vector>
#include <unordered_map>
#include <map>
#include <math.h>
#define ff(i,s,n) for(int i=(s);i<(n);i++)
#define fr(i,s,n) for(int i=(n-1);i>=(s);i--)
#define FF(i,s,n) for(int i=(s);i<=(n);i++)
#define Fr(i,s,n) for(int i=(n);i>=(s);i--)
#define mp(a,b) make_pair(a,b)

template<typename T, typename U> inline void swap(T &a, U &b) {
    a = a^b;
    b = a^b;
    a = a^b;
}

inline void swap(int &a, int &b) {
    a = a^b;
    b = a^b;
    a = a^b;
}

inline void smax(int &a, int b) {
    if (b > a)a = b;
}

inline void smin(int &a, int b) {
    if (b < a)a = b;
}

inline int gcd(int a, int b) {
    if (a < b)swap(a, b);
    while (b > 0) {
        a -= a / b*b;
        swap(a, b);
    }
    return a;
}

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<string, string> > vpss;
typedef vector<pair<int, int> > vpii;
typedef unordered_map<int, int> imap;
typedef unordered_map<long long, long long> lmap;

int readint(){
    int x=0;
    int two=1;
    ff(i,0,10){
        char c;cin>>c;
        x+=c*two;
        two*=2;
    }
    return x;
}
int n,m;vi v;
int main() {
    cin>>n>>m;ff(i,0,n){int t;cin>>t;if(t<0)v.push_back(t);}
    sort(v.begin(),v.end());
    int ac=0;
    ff(i,0,m){
        ac-=v[i];
    }
    cout<<ac;
}


# define M_PI           3.14159265358979323846  /* pi */
#include <cstdio>
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <vector>
#include <unordered_map>
#include <map>
#include <math.h>
#define ff(i,s,n) for(int i=(s);i<(n);i++)
#define fr(i,s,n) for(int i=(n-1);i>=(s);i--)
#define FF(i,s,n) for(int i=(s);i<=(n);i++)
#define Fr(i,s,n) for(int i=(n);i>=(s);i--)
#define mp(a,b) make_pair(a,b)

template<typename T, typename U> inline void swap(T &a, U &b) {
    a = a^b;
    b = a^b;
    a = a^b;
}

inline void swap(int &a, int &b) {
    a = a^b;
    b = a^b;
    a = a^b;
}

inline void smax(int &a, int b) {
    if (b > a)a = b;
}

inline void smin(int &a, int b) {
    if (b < a)a = b;
}

inline int gcd(int a, int b) {
    if (a < b)swap(a, b);
    while (b > 0) {
        a -= a / b*b;
        swap(a, b);
    }
    return a;
}

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<string, string> > vpss;
typedef vector<pair<int, int> > vpii;
typedef unordered_map<int, int> imap;
typedef unordered_map<long long, long long> lmap;

int readint(){
    int x=0;
    int two=1;
    ff(i,0,10){
        char c;cin>>c;
        x+=c*two;
        two*=2;
    }
    return x;
}
int n,m;vi v(0);
int ac=0;
int main() {
    cin>>n>>m;ff(i,0,n){int t;cin>>t;if(t<0)v.push_back(t);}
    sort(v.begin(),v.end());

    ff(i,0,m){
        ac-=v[i];
    }
    cout<<ac;
}


#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string.h>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <math.h>
#include <fstream>

using namespace std;

int main()
{
	int n, *arr, maxx, amount = 0;

	cin >> n >> maxx;
	arr = new int[n];
	for (int i = 0; i < n; i++) cin >> arr[i];

	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (arr[i] < arr[j])
				swap(arr[i], arr[j]);

	for (int i = 0; i < maxx; i++)
	{
		if (arr[i] < 0)
			amount += (-1 * arr[i]);
	}

	cout << amount << endl;

}


#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <iterator>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <sstream>
using namespace std;
#define INF 1000000000
#define MOD 1000000007

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


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

using namespace std;

int main()
{

    int m , n , sum = 0;

    cin >> m >> n ;
    int * arr = new int[m];

    for (int i = 0 ; i < m ; ++i)
        cin >> arr[i];

    sort(arr , arr+m);

    for(int i = 0 ; i < n ; ++i)
        sum+=arr[i];

        cout << abs(sum) << endl;

    return 0;

}


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

using namespace std;

int main()
{

    int m , n , sum = 0;

    cin >> m >> n ;
    int * arr = new int[m];

    for (int i = 0 ; i < m ; ++i)
        cin >> arr[i];

    sort(arr , arr+m);

    for(int i = 0 ; i < n ; ++i)
    {
        if (arr[i] < 0 )
        sum+=arr[i];
     }
        cout << abs(sum) << endl;

    return 0;

}


//Bismillah
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define FOR(i,begin,end) for (ll i=begin;i<=end;i++)
#define rep(i,t) for (ll i=0;i<t;i++)
#define pb push_back
#define sp system("pause");
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(0);
    int n,m;
    cin>>n>>m;
    int a[110];
    rep(i,n) cin>>a[i];
    sort(a,a+n);
    ll res = 0;
    rep(i,m)
    {
            if (a[i]<0)
               res+=abs(a[i]);

    }
    cout<<res<<endl;
    //sp;
    return 0;
}


//Bismillah
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define FOR(i,begin,end) for (ll i=begin;i<=end;i++)
#define rep(i,t) for (ll i=0;i<t;i++)
#define pb push_back
#define sp system("pause");
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(0);
    int n,m;
    cin>>n>>m;
    int a[110];
    rep(i,n) cin>>a[i];
    sort(a,a+n);
    ll res = 0;
    rep(i,m)
            res+=abs(a[i]);
    cout<<res<<endl;
    //sp;
    return 0;
}


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


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


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


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


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


#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define FORI(i,n) for(int i=0; i<n; ++i)
#define FORIR(i,n) for(int i=(n)-1; i>=0; --i)
#define MP(a,b) make_pair(a,b)
#define ALL(L) (L).begin(),(L).end()
#define ALLR(L) (L).rbegin(),(L).rend()
#define SZ(L) (L).size()
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define SORTED_PAIR(a,b) MIN(a,b),MAX(a,b)
#define INF (1<<29)
#define EPS (1e-9)

typedef unsigned int uint;
typedef unsigned long long ull;
typedef signed long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;

int main() {
  int n,m,t,r= 0;
  vector<int> d;
  cin >> n >> m;
  FORI(i,n){
    cin >> t;
    d.push_back(t);
  }
  sort(d.begin(), d.end());
  for(int i = 0; i < m && i < n; ++i) {
    if(d[i] < 0) r -= d[i];
  }
  cout << r << endl;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;

    int tv[n];

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

    sort(tv,tv+n);

    int earn=0;
    for(int i=0; i<m; i++)
    {
        if(tv[i]<0)
            earn+=(tv[i]*-1);
    }

    cout<<earn<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;

    int tv[n];

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

    sort(tv,tv+n);

    int earn=0;
    for(int i=0; i<n; i++)
    {
        if(tv[i]<0)
            earn+=abs(tv[i]);
    }

    cout<<earn<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;

    int tv[n];

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

    sort(tv,tv+n);

    int earn=0;
    for(int i=0; i<n; i++)
    {
        if(tv[i]<0)
            earn+=(tv[i]*-1);
    }

    cout<<earn<<endl;

    return 0;
}


//============================================================================
// Copyright   : Amr
//============================================================================
#include <iostream>
#include <fstream>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;

#define oo (1<<30)
#define sz(v) (int)v.size()
#define pb push_back
#define mp make_pair
#define ppc(x) __builtin_popcount(x)
#define mem(s,v) memset(s,v,sizeof(s))

int main() {
#ifndef ONLINE_JUDGE
    freopen("test.in", "rt", stdin);
#endif
    int a,b;
    cin>>a>>b;
    int t=0;
    vector<int> v(a);
    for(int i=0;i<a;i++)
        cin>>v[i];
    sort(v.begin(),v.end());

    for(int i=0;i<a&&b;i++)
        if(v[i]<0)
            t+=v[i],b--;
        else break;

    cout<<-1*t<<endl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <assert.h>
#include <ctime>
#include <bitset>
#include <numeric>
#include <complex>
typedef long l;
typedef long long ll;
using namespace std;
int main()
{
    int a,b,sum=0;
    cin>>a>>b;
    int z[a];
    for(int i=0; i < a;i++)
        cin>>z[i];
    sort(z,z+a);

    for(int i=0 ; i < b; i++)
        if(z[i]<0)sum+=abs(z[i]);

    cout<<endl<<sum;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <assert.h>
#include <ctime>
#include <bitset>
#include <numeric>
#include <complex>
typedef long l;
typedef long long ll;
using namespace std;
int main()
{
    int a,b,sum=0;
    cin>>a>>b;
    int z[a];
    for(int i=0; i < a;i++)
        cin>>z[i];
    sort(z,z+a);

    for(int i=0 ; i < b; i++)
        sum+=abs(z[i]);
    cout<<endl<<sum;
    return 0;
}


#include <stdio.h>
#include <algorithm>
#include <vector>

using namespace std;

int main( void ) {
     int n, m;

     scanf("%i %i", &n, &m);

     vector<int> p;

     for( int i = 0; i < n; i++ ) {
          int tmp;

          scanf("%i", &tmp);

          p.push_back(tmp);
     }

     sort(p.begin(), p.end());

     int ans = 0;
     for( int i = 0; i < p.size() && m; i++ ) {
          if( p[i] >= 0 ) break;

          ans += (-p[i]);
          m--;
     }

     printf("%i\n", ans);

     return 0;
}


//In the Name of God
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <cctype>
//#include <conio.h>
using namespace std;
#define F(i,l,n) for(int i=l;i<=n;i++)
#define MOD 1000000007
int a[1000000],d=0,b[1000000];
int e[3001][3001];
vector <int> V[3010];
using namespace std;
int main()
{
    int n,k,X,Y,l;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
    	cin>>a[i];
    }
    sort(a+1,a+n+1);
    for(int i=1;i<=k;i++){
    	if(a[i]<0)
    	d+=a[i];
    }
    cout<<abs(d);

}


#include <iostream>
#include <algorithm>

using namespace std;

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

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


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


#include <cstdio>
#include <algorithm>

int prices_[100];

int main() {
  int n, m; std::scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    std::scanf("%d", &prices_[i]);
  }
  std::sort(prices_, prices_ + n);

  int result = 0;
  for (int i = 0; i < n && prices_[i] < 0; ++i) {
    result -= prices_[i];
  }
  std::printf("%d\n", result);
  return 0;
}


#include <cstdio>
#include <algorithm>

int prices_[100];

int main() {
  int n, m; std::scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    std::scanf("%d", &prices_[i]);
  }
  std::sort(prices_, prices_ + n);

  int result = 0;
  for (int i = 0; i < m && prices_[i] < 0; ++i) {
    result -= prices_[i];
  }
  std::printf("%d\n", result);
  return 0;
}


#ifdef pragma_comment_linker
#pragma comment(linker, "/STACK:16777216")
#endif

#define _CRT_SECURE_NO_WARNINGS SHUT_UP_BITCH
#define NDEBUG                  TROLOLO
#define null                    NULL
#define exit_scs                EXIT_SUCCESS

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include <unordered_map>
#include <unordered_set>

#ifdef __LOCAL__
#include <gl/GL.h>
#include <gl/GLU.h>
#include <windows.h>
#endif

using namespace std;

#define all(v)                  (v).begin(), (v).end()
#define db(x)                   cerr << #x << '=' << (x) << "\n"
#define fend(x)                 ((x) & ((x)+1)) - 1
#define fenu(x)                 (x) | ((x)+1)
#define ft                      first
#define len(s)                  s.length()
#define maxV(type)              std::numeric_limits<type>::max()
#define minV(type)              std::numeric_limits<type>::min()
#define mp(a, b)                std::make_pair((a), (b))
#define ord(c)                  ((c) - 'a' + 1)
#define pob()                   pop_back()
#define pof()                   pop_front()
#define pub(s)                  push_back((s))
#define puf(s)                  push_front((s))
#define sc                      second

typedef double                  f32;
typedef long double             f64;
typedef short int               i16;
typedef long long               i64;
typedef unsigned long long      u64;

const   long double             EPS = 0.00001;
const   long double             PI = 3.14159265358979323846;

int lg2(i64 n) { int h = 0; while ((1 << h) < n) ++h; return h; }

inline void file_io(string in_file, string out_file, bool mark) {
	if (!mark) return;
	freopen(in_file.c_str(), "r", stdin);
	freopen(out_file.c_str(), "w", stdout);
}

/* correct erase_all_spaces() realisation */
void erase_all_spaces(string& expr) {
	size_t pnt = 0;
	for (size_t i = 0; i < expr.length(); ++i) {
		if (expr[i] != ' ')
			expr[pnt++] = expr[i];
	}
	expr.resize(pnt);
}

int main() {
	file_io("unequal.in", "unequal.out", 0);
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<int> v(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i];
	sort(all(v));
	int ans = 0;
	for (int i = 0; i < min(m, n); ++i) {
		if (v[i] < 0)
			ans += -v[i];
	}
	cout << ans << endl;
	return 0;
}


#ifdef pragma_comment_linker
#pragma comment(linker, "/STACK:16777216")
#endif

#define _CRT_SECURE_NO_WARNINGS SHUT_UP_BITCH
#define NDEBUG                  TROLOLO
#define null                    NULL
#define exit_scs                EXIT_SUCCESS

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include <unordered_map>
#include <unordered_set>

#ifdef __LOCAL__
#include <gl/GL.h>
#include <gl/GLU.h>
#include <windows.h>
#endif

using namespace std;

#define all(v)                  (v).begin(), (v).end()
#define db(x)                   cerr << #x << '=' << (x) << "\n"
#define fend(x)                 ((x) & ((x)+1)) - 1
#define fenu(x)                 (x) | ((x)+1)
#define ft                      first
#define len(s)                  s.length()
#define maxV(type)              std::numeric_limits<type>::max()
#define minV(type)              std::numeric_limits<type>::min()
#define mp(a, b)                std::make_pair((a), (b))
#define ord(c)                  ((c) - 'a' + 1)
#define pob()                   pop_back()
#define pof()                   pop_front()
#define pub(s)                  push_back((s))
#define puf(s)                  push_front((s))
#define sc                      second

typedef double                  f32;
typedef long double             f64;
typedef short int               i16;
typedef long long               i64;
typedef unsigned long long      u64;

const   long double             EPS = 0.00001;
const   long double             PI = 3.14159265358979323846;

int lg2(i64 n) { int h = 0; while ((1 << h) < n) ++h; return h; }

inline void file_io(string in_file, string out_file, bool mark) {
	if (!mark) return;
	freopen(in_file.c_str(), "r", stdin);
	freopen(out_file.c_str(), "w", stdout);
}

/* correct erase_all_spaces() realisation */
void erase_all_spaces(string& expr) {
	size_t pnt = 0;
	for (size_t i = 0; i < expr.length(); ++i) {
		if (expr[i] != ' ')
			expr[pnt++] = expr[i];
	}
	expr.resize(pnt);
}

int main() {
	file_io("unequal.in", "unequal.out", 0);
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<int> v(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i];
	sort(all(v));
	int ans = 0;
	for (int i = 0; i < m; ++i) {
		if (v[i] < 0)
			ans += -v[i];
	}
	cout << ans << endl;
	return 0;
}


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

int main(void)
{
	int n, m;
	cin >> n >> m;
	vector<int> v(n);
	for (int i = 0; i != n; ++i)
		cin >> v[i];

	sort(v.begin(), v.end());
	int s = 0;
	for (int i = 0; i != n && v[i] < 0; ++i)
		s -= v[i];

	cout << s << endl;
	return 0;
}


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

int main(void)
{
	int n, m;
	cin >> n >> m;
	vector<int> v(n);
	for (int i = 0; i != n; ++i)
		cin >> v[i];

	sort(v.begin(), v.end());
	int s = 0;
	for (int i = 0; i != n && v[i] < 0 && i < m; ++i)
		s -= v[i];

	cout << s << endl;
	return 0;
}


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

typedef long long ll;
#define sz(v) (int)v.size()

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> v(n);
	for(int i = 0; i < n; i++) cin >> v[i];
	sort(v.begin(), v.end());
	int sum = 0;
	for(int i = 0; i < m; i++) if(v[i] <= 0) sum += abs(v[i]);
	cout << sum << endl;
}


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

typedef long long ll;
#define sz(v) (int)v.size()

char num[121000][25];

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i = 0; i < n; i++) cin >> v[i];
	sort(v.begin(), v.end());
	int sum = 0;
	for(int i = 0; i < m; i++) if(v[i] <= 0) sum += abs(v[i]);
	cout << sum << endl;
}


#include<bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0, _n = (int)(n); i < _n; i++)
#define fff(i, x, n) for (int i = (int)(x), _n = (int)(n); i < _n; i++)
#define ford(i, n, x) for (int i = (int)(n), _x = (int)(x); i >= _x; i--)
#define fmp(i, x) for (__typeof(x.begin()) i = x.begin(); i != x.end(); i++)
#define len(x) (int((x).size()))
#define pb push_back
#define fx(x) fixed<<setprecision(x)
#define mkp make_pair
#define all(X) (X).begin(),(X).end()
#define bug     cerr << ""
#define see(x) cerr << #x << "= " << x << endl
#define clr(a, b) memset(a, b, sizeof(a))

#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> pii;

const int NN = 1e3 + 20;
const double pi = acos(-1.) ;

template <class T> inline void smin(T &a, T b){ if(b<a) a = b;}
template <class T> inline void smax(T &a, T b){ if(a<b) a = b;}
///////////////////////////////////////////////////////////////
int tv[NN];
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, m ; cin >> n >> m;
    rep(i, n) {
        cin >> tv[i];
    }
    sort(tv, tv+n) ;
    int tot=0;
    rep(i, m) {
        if(tv[i] < 0) {
            tot += (tv[i] * -1);
        }
    }
    cout << tot << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0, _n = (int)(n); i < _n; i++)
#define fff(i, x, n) for (int i = (int)(x), _n = (int)(n); i < _n; i++)
#define ford(i, n, x) for (int i = (int)(n), _x = (int)(x); i >= _x; i--)
#define fmp(i, x) for (__typeof(x.begin()) i = x.begin(); i != x.end(); i++)
#define len(x) (int((x).size()))
#define pb push_back
#define fx(x) fixed<<setprecision(x)
#define mkp make_pair
#define all(X) (X).begin(),(X).end()
#define bug     cerr << ""
#define see(x) cerr << #x << "= " << x << endl
#define clr(a, b) memset(a, b, sizeof(a))

#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> pii;

const int NN = 1e3 + 20;
const double pi = acos(-1.) ;

template <class T> inline void smin(T &a, T b){ if(b<a) a = b;}
template <class T> inline void smax(T &a, T b){ if(a<b) a = b;}
///////////////////////////////////////////////////////////////
int tv[NN];
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, m ; cin >> n >> m;
    rep(i, n) {
        cin >> tv[i];
    }
    sort(tv, tv+n) ;
    int tot=0;
    rep(i, m) {
        if(tv[i] < 0) {
            tot += (tv[i] * -1);
        }
        else if(tv[i] > 0) {
            tot += (tv[i] * -1);
        }
    }
    cout << tot << endl;
    return 0;
}


#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <valarray>
#include<map>
#include<set>
#include <unordered_set>
#include <fstream>
using namespace std;
int main()
{

    int n,m;
    cin>>n>>m;
    long long tot=0;
    int x;
    int j=0;
    vector<int>v(m+100,0);
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(x<0)
        {
            v[j]=x;
            j++;
        }
    }
    sort(v.begin(),v.end());
    for(int i=0;i<m;i++)
    {
        tot+=v[i];
    }
    cout<<tot*-1<<endl;

    return 0;
}


#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <valarray>
#include<map>
#include<set>
#include <unordered_set>
#include <fstream>
using namespace std;
int main()
{

    int n,m;
    cin>>n>>m;
    int tot=0;
    int x;
    int j=0;
    vector<int>v(m,0);
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(x<0)
        {
            v[j]=x;
            j++;
        }
    }
    sort(v.begin(),v.end());
    for(int i=0;i<m;i++)
    {
        tot+=v[i];
    }
    cout<<tot*-1<<endl;

    return 0;
}


#include<stdio.h>
#define nmax 1000
int m,n;
float t[nmax];
float som;

void saisie(int *n ,int *m)
{
	do
	{
	printf("donner la quantit� de TV � vendre: \n ");
	scanf("%d",n);
	printf("donner la quantit� de TV � acheter: \n");
	scanf("%d",m);
    }
    while((1>*m) | (*n<*m)|(*n>1000));

}

void saisieprices(int n,float t[])
{
	int i=0;
	for(i=0;i<n;i++)
	{
	do
	{
	printf("donner le prix num %d :\n",i);
	scanf("%f",&t[i]);
    }
    while((t[i]<-nmax)||(t[i]>nmax));
    }
}
void tri(float tab[],int n)
{
int i,c=0,test;

do
{   test=0;
	for(i=0;i<n-1;i++)
	{
	if(tab[i]>tab[i+1])
	{
	c=tab[i+1];
	tab[i+1]=tab[i];
	tab[i]=c;
	test=1;
	}
    }
}
while(test);

}
void Bob(float t[],float *som)
{
	int i=0;

	for(i=0;i<m;i++)
	{
	if(t[i]<0)
	*som=*som-t[i];
	else if(t[i]>0)
	*som=*som-t[i];
	}

}
int main()
{
	saisie(&n,&m);
	/*printf("%d %d :\n",n,m);*/
	saisieprices(n,t);
	tri(t,n);
	Bob(t,&som);
	printf("la somme est: %f",som);
	return 0;
}


#include<stdio.h>
#define nmax 1000
int m,n;
int t[nmax];
int som=0;

void saisie(int *n ,int *m)
{
    do
    {

    scanf("%d",n);

    scanf("%d",m);
    }
    while((1>*m) || (*n<*m) || (*n>1000));

}

void saisieprices(int n,int t[])
{
    int i=0;
    for(i=0;i<n;i++)
    {
    do
    {

    scanf("%d",&t[i]);
    }
    while((t[i]<-nmax)||(t[i]>nmax));
    }
}
void tri(int tab[],int n)
{
int i,c=0,test;

do
{   test=0;
    for(i=0;i<n-1;i++)
    {
    if(tab[i]>tab[i+1])
    {
    c=tab[i+1];
    tab[i+1]=tab[i];
    tab[i]=c;
    test=1;
    }
    }
}
while(test);

}
void Bob(int t[],int *som)
{
    int i=0;

    for(i=0;i<m;i++)
    {
        if (t[i]<0)
        *som=*som-t[i];
    }

}
int main()
{
    saisie(&n,&m);
    /*printf("%d %d :\n",n,m);*/
    saisieprices(n,t);
    tri(t,n);
    Bob(t,&som);
    printf("%d",som);
    return 0;
}


#include<stdio.h>
#define nmax 1000
int m,n;
int t[nmax];
int som=0;

void saisie(int *n ,int *m)
{
	do
	{
	printf("donner la quantit� de TV � vendre: \n ");
	scanf("%d",n);
	printf("donner la quantit� de TV � acheter: \n");
	scanf("%d",m);
    }
    while((1>*m) | (*n<*m)|(*n>1000));

}

void saisieprices(int n,int t[])
{
	int i=0;
	for(i=0;i<n;i++)
	{
	do
	{
	printf("donner le prix num %d :\n",i);
	scanf("%d",&t[i]);
    }
    while((t[i]<-nmax)||(t[i]>nmax));
    }
}
void tri(int tab[],int n)
{
int i,c=0,test;

do
{   test=0;
	for(i=0;i<n-1;i++)
	{
	if(tab[i]>tab[i+1])
	{
	c=tab[i+1];
	tab[i+1]=tab[i];
	tab[i]=c;
	test=1;
	}
    }
}
while(test);

}
void Bob(int t[],int *som)
{
	int i=0;

	for(i=0;i<m;i++)
	{
		if (t[i]<0)
		*som=*som-t[i];
	}

}
int main()
{
	saisie(&n,&m);
	/*printf("%d %d :\n",n,m);*/
	saisieprices(n,t);
	tri(t,n);
	Bob(t,&som);
	printf("la somme est: %d",som);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int a[n],i,j,sum=0;

    for(i=0;i<n;i++)
    {
                    cin>>a[i];

    }

  sort(a,a+n);
  for(j=0;j<m;j++)
  {
                  if(a[j]>0)
                  break;
                  sum+=a[j];
                  }
   cout<<abs(sum)<<endl;
  // system("pause");
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
   int n,m,temp;
   int * data;
   bool swap = true;

   cin >> n;
   cin >> m;

   data = new int[n];

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

   if (n == 1)
   {
       if (data[0] < 0)
       {
           cout << data[0];
       }
       else
       {
           cout << 0;
       }
       return 0;
   }

   while (swap)
   {
       swap = false;
       for (int i = 0; i < n - 1;i++)
       {

           if (data[i] > data[i+1])
           {
               temp = data[i];
               data[i] = data[i+1];
               data[i+1] = temp;
               swap = true;
           }

       }
   }

   temp = 0;
   for (int i = 0; i < m; i++)
   {
       if (data[i] < 0)
       {
           temp += data[i];
       }
   }

   cout << -1*temp;

   return 0;
}


#include <iostream>
using namespace std;
int main()
{
   int n,m,temp;
   int * data;
   bool swap = true;

   cin >> n;
   cin >> m;

   data = new int[n];

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

   if (n == 1)
   {
       if (data[0] < 0)
       {
           cout << -1*data[0];
       }
       else
       {
           cout << 0;
       }
       return 0;
   }

   while (swap)
   {
       swap = false;
       for (int i = 0; i < n - 1;i++)
       {

           if (data[i] > data[i+1])
           {
               temp = data[i];
               data[i] = data[i+1];
               data[i+1] = temp;
               swap = true;
           }

       }
   }

   temp = 0;
   for (int i = 0; i < m; i++)
   {
       if (data[i] < 0)
       {
           temp += data[i];
       }
   }

   cout << -1*temp;

   return 0;
}


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

int main()
{
    int n,m,sum=0;
    cin>>n>>m;
     vector<int>x(n);
 for(int i=0;i<n;i++)
    cin>>x[i];
 sort(x.begin(),x.end());
 for(int i=0;i<m;i++)
 {
     if(x[i]>-1)
        break;
     sum+=abs(x[i]);
 }
 cout<<sum<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define cnt(x , n) count(x.begin(),x.end(),n)
#define so(x) sort(x.begin(),x.end())
#define rso(x) sort(x.rbegin(),x.rend())
#define mx(x) *max_element(x.begin(),x.end())
#define mn(x) *min_element(x.begin(),x.end())
#define rev(x) reverse(x.begin(),x.end())
#define pb push_back
#define al(n) (n).begin(),(n).end()
#define ral(n) (n).rbegin(),(n).rend()
#define mp make_pair
#define sz size()
#define F first
#define S second
#define rFoR(i,x,n) for(int i=x;i>n;--i)
#define FoR(i,x,n) for(int i = x; i < n; i++)
#define bo bool
#define RE(s) freopen(s, "r", stdin)
#define WR(s) freopen(s, "w", stdout)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
int main() {
#ifndef ONLINE_JUDGE
	RE("text.txt");
#endif
	int n, m, res = 0;
	scanf("%d%d", &n, &m);
	vector<int> v(n);
	FoR(i,0,n)
	{
		cin >> v[i];
		v[i] *= -1;
	}
	rso(v);
	FoR(i,0,m)
		res += (v[i]);
	printf("%d\n", res);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define cnt(x , n) count(x.begin(),x.end(),n)
#define so(x) sort(x.begin(),x.end())
#define rso(x) sort(x.rbegin(),x.rend())
#define mx(x) *max_element(x.begin(),x.end())
#define mn(x) *min_element(x.begin(),x.end())
#define rev(x) reverse(x.begin(),x.end())
#define pb push_back
#define al(n) (n).begin(),(n).end()
#define ral(n) (n).rbegin(),(n).rend()
#define mp make_pair
#define sz size()
#define F first
#define S second
#define rFoR(i,x,n) for(int i=x;i>n;--i)
#define FoR(i,x,n) for(int i = x; i < n; i++)
#define bo bool
#define RE(s) freopen(s, "r", stdin)
#define WR(s) freopen(s, "w", stdout)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
int arr[101];
int main() {
#ifndef ONLINE_JUDGE
	RE("text.txt");
#endif
	int n, m , res = 0;
	scanf("%d%d",&n,&m);
	FoR(i,0,n)
		cin>>arr[i];
	sort(arr,arr+n);
	FoR(i,0,m)
		res+=(arr[i]*-1);
	printf("%d\n",res);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define cnt(x , n) count(x.begin(),x.end(),n)
#define so(x) sort(x.begin(),x.end())
#define rso(x) sort(x.rbegin(),x.rend())
#define mx(x) *max_element(x.begin(),x.end())
#define mn(x) *min_element(x.begin(),x.end())
#define rev(x) reverse(x.begin(),x.end())
#define pb push_back
#define al(n) (n).begin(),(n).end()
#define ral(n) (n).rbegin(),(n).rend()
#define mp make_pair
#define sz size()
#define F first
#define S second
#define rFoR(i,x,n) for(int i=x;i>n;--i)
#define FoR(i,x,n) for(int i = x; i < n; i++)
#define bo bool
#define RE(s) freopen(s, "r", stdin)
#define WR(s) freopen(s, "w", stdout)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
int main() {
#ifndef ONLINE_JUDGE
	RE("text.txt");
#endif
	int n, m, res = 0;
	scanf("%d%d", &n, &m);
	vector<int> v(n);
	FoR(i,0,n)
	{
		cin >> v[i];
		v[i] *= -1;
	}
	rso(v);
	FoR(i,0,m){
		if(v[i] < 0)
			break;
		res += (v[i]);
	}
	printf("%d\n", res);
	return 0;
}


#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <bitset>
#include <algorithm>
#include <cstring>

using namespace std;

#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i, a, b) for(int i = (a) - 1; i >= b; --i)
#define trav(it, v) for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define all(v) (v).begin(), (v).end()

typedef double fl;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

template<typename T>
istream& operator>>(istream& in, vector<T> &v) {
    rep(i,0,v.size()) in >> v[i];
    return in;
}

template<typename A, typename B>
istream& operator>>(istream& in, pair<A, B> &p) {
    in >> p.first >> p.second;
    return in;
}

template<typename T>
ostream& operator<<(ostream& out, vector<T> &v) {
    if(v.size()) out << v[0];
    rep(i,1,v.size()) out << ' ' << v[i];
    return out;
}

template<typename A, typename B>
ostream& operator<<(ostream& out, pair<A, B> &p){
    out << p.first << ' ' << p.second;
    return out;
}

void solve(){
    int n, m;
    cin >> n >> m;
    vi a(n);
    cin >> a;
    sort(all(a));
    int ans = 0;
    rep(i,0,m)
        if(a[i] < 0) ans -= a[i];
    cout << ans << endl;
}

int main(){
    cin.tie(0);
    cout.tie(0);
    cin.sync_with_stdio(false);
    solve();
}


#include<bits/stdc++.h>

using namespace std;

const double EPS = 1e-9;
const int IINF = 1000000000;
const double PI = acos(-1.0);
const long long LINF = 6000000000000000000LL;

int main() {
#ifdef _DEBUG_
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n, m;
    while(scanf("%d%d", &n, &m) == 2) {
        vector<int> v(n);
        for(int i = 0; i < n; ++i) {
            scanf("%d", &v[i]);
        }
        sort(v.begin(), v.end());
        int answer = 0;
        while(m-- > 0 && v[0] < 0) {
            answer += abs(v[0]);
            v.erase(v.begin());
        }
        printf("%d\n", answer);
    }

    return 0;
}


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

int main()
{
    int n,m;

    cin>>n>>m ;
    vector <int> v(n);

    for(int i=0 ; i<n ; i++)
        cin>>v[i];

    sort(v.begin(),v.end());

    int sum=0;
    for(int i=0 ;i<n && i<m; i++)
    {
        if(v[i]>0)
        break;
        sum=sum+v[i];
    }
    cout<<abs(sum)<<endl;
    return 0;
}


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

int main()
{
    int n,m;

    cin>>n>>m ;
    vector <int> v(n);

    for(int i=0 ; i<n ; i++)
        cin>>v[i];

    sort(v.begin(),v.end());

    int sum=0;
    for(int i=0 ;i<n && i<m; i++)
    {
        if(v[i]>0)
        break;
        sum=sum+v[i];
    }
    cout<<abs(sum)<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <stack>
#include <functional>
#include <queue>
#include <stack>
#include <sstream>
#include <map>
#include <set>
#include <numeric>
#include <iomanip>
#include <string.h>
using namespace std;
#define sorta(x) sort(x.begin(),x.end())
#define sortd(x) sort(x.begin(),x.end(),greater<int>())
#define pb push_back
#define mp make_pair
int main() {
    int n, m; cin >> n >> m;
    vector<int>x(n);
    for (int i = 0; i < n; cin >> x[i++]);
    sorta(x);
    int counter = m, i = 0, sum = 0, maxi = 0;
    while (counter>0) {
        sum += x[i++] * -1, counter--;
        if (maxi < sum) maxi = sum;
    }
    cout << maxi << endl;
    return 0;
}