function main( input ){

  input = input.split( /\n/ )

  var nk = input[0].split( /\s/ )
  var ls = input[1].split( /\s/ )

  var N = Number( nk[0] )
  var K = Number( nk[1] )

  for( var i=0; i<ls.length; i++ )
    ls[i] = Number( ls[i] )

  ls.sort( function( a, b ){
    if( a > b ) return -1
    if( a < b ) return  1
    return 0
  } )

  var sum = 0
  ls = ls.splice( 0, K )

  for( var i=0; i<ls.length; i++ )
    sum += ls[i]

  console.log( sum )

}

main(
  require( 'fs' )
    .readFileSync( '/dev/stdin', 'utf8' )
)
