Imports System
Imports System.Text.RegularExpressions

Module Program
    Sub Main(args As String())

        Dim sInputA As String() = Console.ReadLine().Split(" ")
        Dim sInputB As String() = Console.ReadLine().Split(" ")

        Dim resultA() As Integer = Array.ConvertAll(Of String, Integer)(sInputA, AddressOf Integer.Parse)
        Dim resultB() As Integer = Array.ConvertAll(Of String, Integer)(sInputB, AddressOf Integer.Parse)


        Array.Sort(resultB)

        Dim sum As Integer

        For i = 0 To resultA(1) - 1
            sum += resultB(i)
        Next

        Console.WriteLine(sum)

  
    End Sub
End Module
