#include using namespace std; #define rep(i,n) for(long long i=0;i=0;i--) #define REPR(i,s,n) for(long long i=(s);i>=(n);i--) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define Eunique(v) v.erase(unique(all(v)),v.end()) #define Eback(s) s.erase(s.end()-1,s.end()) #define minvec(v) *min_element(all(v)) #define maxvec(v) *max_element(all(v)) #define sumvec(v) accumulate(all(v),0LL) #define pb push_back #define pf push_front #define m_p make_pair #define DOUBLE fixed << setprecision(15) #define OK cerr<<"OK\n" #define OK1 cerr<<"OK1\n" #define OK2 cerr<<"OK2\n" #define sz(s) (long long)s.size() #define INF ((1LL<<62)-(1LL<<31)) #define zero(x,n) setw(x) << setfill('0') << n //#define endl '\n' typedef long long ll; typedef long double ld; typedef vector vi; typedef vector vll; typedef vector vd; typedef vector vc; typedef vector vb; typedef vector vs; typedef vector vvi; typedef vector vvll; typedef vector vvd; typedef vector vvc; typedef vector vvb; typedef pair P; typedef vector

vP; template ostream& operator<<(ostream& ost, const pair&p) { ost << "{" << p.first << ", " << p.second << "} "; return ost; } template ostream& operator<<(ostream& ost, const vector&v) { ost << "{"; for (int i = 0; i<(int)v.size(); i++) { if (i)ost << " "; ost << v[i]; } ost << "} \n"; return ost; } template ostream& operator<<(ostream& ost, const map&v) { ost << "{"; for (auto p:v) { ost << "{" << p.first << ", " << p.second << "} "; } ost << "} "; return ost; } void out(){cout << "\n";} template void out(const T &x,const Args &... args){ cout << x << " "; out(args...); } template istream& operator >> (istream& is, vector& vec){ for(T& e: vec) is >> e; return is; } template string join(vector& vec, string sep=" "){ stringstream ss; for(int i=0;i<(int)vec.size();i++){ ss << vec[i] << (i+1==(int)vec.size()?"\n":sep); } return ss.str(); } template inline bool chmax(T& a, T b){if(a inline bool chmin(T& a, T b){if(a>b){a=b;return true;} return false;} #define INT(...) int __VA_ARGS__;IN(__VA_ARGS__) #define LL(...) long long __VA_ARGS__;IN(__VA_ARGS__) #define CHR(...) char __VA_ARGS__;IN(__VA_ARGS__) #define DBL(...) double __VA_ARGS__;IN(__VA_ARGS__) #define STR(...) string __VA_ARGS__;IN(__VA_ARGS__) #define LD(...) long double __VA_ARGS__;IN(__VA_ARGS__) void scan(int& a){ cin >> a; } void scan(long long& a){ cin >> a; } void scan(char& a){ cin >> a; } void scan(double& a){ cin >> a; } void scan(string& a){ cin >> a; } void scan(long double& a){ cin >> a; } void IN(){} template void IN(Head& head,Tail&... tail){ scan(head); IN(tail...); } void YES(bool b) {cout << ((b)?"YES\n":"NO\n");} void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");} void yes(bool b) {cout << ((b)?"yes\n":"no\n");} void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");} const long double pi = acos(-1.0); const ll mod=1000000007; //const ll mod=998244353; ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;} ll nCrmod(ll n,ll r){ll x=1,y=1; for(ll i=0;i prime_factor(ll n){ map m; for(ll i=2;i*i<=n;i++){ while(n%i==0){ m[i]++; n/=i; } } if(n!=1) m[n]=1; return m; } int main() { LL(n, k); vll a(n); cin >> a; sort(rall(a)); ll ans = 0; rep(i, k) { if(a[i] > 0) ans += a[i]; } cout << ans << endl; return 0; }