#include #include #include #include #include #define all(x) x.begin(),x.end() #define pb push_back #define ll long long using namespace std; int main() { int n,k; int sum = 0; cin >> n>>k; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(all(a), greater<>()); for (int i = 0; i < k; i++) { if (a[i] >= 0) sum += a[i]; else if (a[0] < 0) sum += a[0]; } cout << sum << endl; return 0; }