// No.1046 Fruits Rush #include #define rep(i, n) for(int i=0; i<(int)(n); i++) using namespace std; using ll = long long; using ull = unsigned long long; int main(){ int n, k; cin >> n >> k; vector a(n); rep(i, n) cin >> a[i]; int ans = 0; sort(a.rbegin(), a.rend()); rep(i, k){ if(ans < ans+a[i]) ans += a[i]; } cout << ans << endl; return 0; }