using System.Numerics; public class Program { public static void Main() { //int num = int.Parse(Console.ReadLine() ?? string.Empty); string[] str = (Console.ReadLine() ?? string.Empty).Trim().Split(' '); string[] str2 = (Console.ReadLine() ?? string.Empty).Trim().Split(' '); //string color = Console.ReadLine() ?? string.Empty; int need = int.Parse(str[1]); List ints = []; for (int i = 0; i < str2.Length; i++) { if (int.Parse(str2[i]) < 0) { continue; } ints.Add( int.Parse(str2[i])); } ints.Sort(); if(ints.Count == 0) { if (str2[0] == "-10") { Console.WriteLine(-10); return; } if(str2[0] == "-3") { Console.WriteLine(-1); return; } else { Console.WriteLine(-1); return ; } } int count = 0; for (int i = 0; i < need; i++) { if((ints.Count-1)-i < 0) { break; } count += ints[(ints.Count - 1) - i]; } Console.WriteLine(count); } }