using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

namespace Carobnjak
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string prva = Console.ReadLine();
            int N = int.Parse(prva.Split()[0]);
            int K = int.Parse(prva.Split()[1]);
            string druga = Console.ReadLine();
            List<int> napitci = new List<int>();
            int max;
            for (int i = 0; i < N; i++)
            {
                int x = int.Parse(druga.Split()[i]);
                napitci.Add(x);
            }
            max = napitci.Max();
            napitci.Remove(max);
            for (int i = 0; i < K-1; i++)
            {
                int x = napitci.Min();
                max -= x;
                napitci.Remove(x);
            }
            Console.WriteLine(max);
        }
    }
}