use std::io;
use std::str::FromStr;

fn main() {
    let (n, k) = {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let mut it = buf.split_whitespace();
        (
            i32::from_str(it.next().unwrap()).unwrap(),
            i32::from_str(it.next().unwrap()).unwrap(),
        )
    };
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let mut p: Vec<i32> = buf.split_whitespace().map(|s| s.parse().unwrap()).collect();
    if n == 1 {
        println!("{}", p.get(0).unwrap());
    }
    p.sort();
    let mut i = 0;
    let mut ans = 0;
   for a in p.iter() {
        if (i >= k) {
            println!("{}", ans);
            return
        }
        ans = ans + a;
        i = i + 1;
    }
}
