#include #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair ; using pll = pair; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; int main(){ int n,k; cin >> n >> k; vector a(n); rep(i,n) cin >> a[i]; sort(a.begin(),a.end(),greater()); int ans =0; rep(i,min(n,k)){ if(a[i] > 0) ans += a[i]; else break; } cout << ans << endl; return 0; }