#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; int main(){ ll n,k; cin >> n >> k; vector a(n); for(int i = 0;i < n;i++)cin >> a[i]; sort(a.rbegin(),a.rend()); ll res = 0; for(int i = 0;i < k;i++){ if(a[i] <= 0 && i != 0)break; res += a[i]; } cout << res << endl; }