import std; int calc(int k, int[] a) { a.sort!"a > b"; auto ans = a[0] + a[1..$].until!"a < 0".take(k-1).sum; return ans; } void main() { int n, k; scan(n, k); auto a = readints; writeln(calc(k, a)); } void scan(T...)(ref T a) { string[] ss = readln.split; foreach (i, t; T) a[i] = ss[i].to!t; } T read(T=string)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readints = reads!int;