import java.util.Scanner;

public class Main 
{
	
	public static void main(String[] args)
	{
		
		int count = 0;
		int temp = 1000;
		int tempo = 0;
		int answer = 0;
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] p = new int[n];
		
		for(int i = 0; i < n; i++)
		{
			p[i] = sc.nextInt();
		}
		sc.close();
		
		while(count < k)
		{
			for(int i = 0; i < n; i++)
			{
				
				if(temp > p[i] && p[i] != 0)
				{
					temp = p[i];
					tempo = i;
				}
				if(i + 1 == n)
				{
					p[tempo] = 1000;
				}

			}
			
			answer += temp;
			temp = 1000;
			count++;

		}
		
		System.out.println(answer);
		
	}

} import java.util.Scanner; Scanner java.util public class Main 
{
	
	public static void main(String[] args)
	{
		
		int count = 0;
		int temp = 1000;
		int tempo = 0;
		int answer = 0;
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] p = new int[n];
		
		for(int i = 0; i < n; i++)
		{
			p[i] = sc.nextInt();
		}
		sc.close();
		
		while(count < k)
		{
			for(int i = 0; i < n; i++)
			{
				
				if(temp > p[i] && p[i] != 0)
				{
					temp = p[i];
					tempo = i;
				}
				if(i + 1 == n)
				{
					p[tempo] = 1000;
				}

			}
			
			answer += temp;
			temp = 1000;
			count++;

		}
		
		System.out.println(answer);
		
	}

} Main public static void main(String[] args)
	{
		
		int count = 0;
		int temp = 1000;
		int tempo = 0;
		int answer = 0;
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] p = new int[n];
		
		for(int i = 0; i < n; i++)
		{
			p[i] = sc.nextInt();
		}
		sc.close();
		
		while(count < k)
		{
			for(int i = 0; i < n; i++)
			{
				
				if(temp > p[i] && p[i] != 0)
				{
					temp = p[i];
					tempo = i;
				}
				if(i + 1 == n)
				{
					p[tempo] = 1000;
				}

			}
			
			answer += temp;
			temp = 1000;
			count++;

		}
		
		System.out.println(answer);
		
	} main {
		
		int count = 0;
		int temp = 1000;
		int tempo = 0;
		int answer = 0;
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] p = new int[n];
		
		for(int i = 0; i < n; i++)
		{
			p[i] = sc.nextInt();
		}
		sc.close();
		
		while(count < k)
		{
			for(int i = 0; i < n; i++)
			{
				
				if(temp > p[i] && p[i] != 0)
				{
					temp = p[i];
					tempo = i;
				}
				if(i + 1 == n)
				{
					p[tempo] = 1000;
				}

			}
			
			answer += temp;
			temp = 1000;
			count++;

		}
		
		System.out.println(answer);
		
	} int count = 0; count 0 int temp = 1000; temp 1000 int tempo = 0; tempo 0 int answer = 0; answer 0 Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int k = sc.nextInt(); k sc.nextInt() sc.nextInt sc int[] p = new int[n]; p new int[n] n for(int i = 0; i < n; i++)
		{
			p[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			p[i] = sc.nextInt();
		} {
			p[i] = sc.nextInt();
		} p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc sc.close() sc.close sc while(count < k)
		{
			for(int i = 0; i < n; i++)
			{
				
				if(temp > p[i] && p[i] != 0)
				{
					temp = p[i];
					tempo = i;
				}
				if(i + 1 == n)
				{
					p[tempo] = 1000;
				}

			}
			
			answer += temp;
			temp = 1000;
			count++;

		} count < k count k {
			for(int i = 0; i < n; i++)
			{
				
				if(temp > p[i] && p[i] != 0)
				{
					temp = p[i];
					tempo = i;
				}
				if(i + 1 == n)
				{
					p[tempo] = 1000;
				}

			}
			
			answer += temp;
			temp = 1000;
			count++;

		} for(int i = 0; i < n; i++)
			{
				
				if(temp > p[i] && p[i] != 0)
				{
					temp = p[i];
					tempo = i;
				}
				if(i + 1 == n)
				{
					p[tempo] = 1000;
				}

			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				
				if(temp > p[i] && p[i] != 0)
				{
					temp = p[i];
					tempo = i;
				}
				if(i + 1 == n)
				{
					p[tempo] = 1000;
				}

			} {
				
				if(temp > p[i] && p[i] != 0)
				{
					temp = p[i];
					tempo = i;
				}
				if(i + 1 == n)
				{
					p[tempo] = 1000;
				}

			} if(temp > p[i] && p[i] != 0)
				{
					temp = p[i];
					tempo = i;
				} temp > p[i] && p[i] != 0 temp > p[i] temp p[i] p i p[i] != 0 p[i] p i 0 {
					temp = p[i];
					tempo = i;
				} temp = p[i] temp p[i] p i tempo = i tempo i if(i + 1 == n)
				{
					p[tempo] = 1000;
				} i + 1 == n i + 1 i 1 n {
					p[tempo] = 1000;
				} p[tempo] = 1000 p[tempo] p tempo 1000 answer += temp answer temp temp = 1000 temp 1000 count++ count System.out.println(answer) System.out.println System.out System System.out answer String[] args args public class Main 
{
	
	public static void main(String[] args)
	{
		
		int count = 0;
		int temp = 1000;
		int tempo = 0;
		int answer = 0;
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] p = new int[n];
		
		for(int i = 0; i < n; i++)
		{
			p[i] = sc.nextInt();
		}
		sc.close();
		
		while(count < k)
		{
			for(int i = 0; i < n; i++)
			{
				
				if(temp > p[i] && p[i] != 0)
				{
					temp = p[i];
					tempo = i;
				}
				if(i + 1 == n)
				{
					p[tempo] = 1000;
				}

			}
			
			answer += temp;
			temp = 1000;
			count++;

		}
		
		System.out.println(answer);
		
	}

} public class Main 
{
	
	public static void main(String[] args)
	{
		
		int count = 0;
		int temp = 1000;
		int tempo = 0;
		int answer = 0;
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] p = new int[n];
		
		for(int i = 0; i < n; i++)
		{
			p[i] = sc.nextInt();
		}
		sc.close();
		
		while(count < k)
		{
			for(int i = 0; i < n; i++)
			{
				
				if(temp > p[i] && p[i] != 0)
				{
					temp = p[i];
					tempo = i;
				}
				if(i + 1 == n)
				{
					p[tempo] = 1000;
				}

			}
			
			answer += temp;
			temp = 1000;
			count++;

		}
		
		System.out.println(answer);
		
	}

} Main
import java.util.Scanner;

public class Main 
{
	
	public static void main(String[] args)
	{
		
		int count = 0;
		int temp = 1000;
		int tempo = 0;
		int answer = 0;
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] p = new int[n];
		
		for(int i = 0; i < n; i++)
		{
			p[i] = sc.nextInt();
		}
		sc.close();
		
		while(count < k)
		{
			for(int i = 0; i < n; i++)
			{
				
				if(temp > p[i] && p[i] != 0)
				{
					temp = p[i];
					tempo = i;
				}
				if(i + 1 == n)
				{
					p[tempo] = 1000;
				}

			}
			
			answer += temp;
			temp = 1000;
			count++;

		}
		
		System.out.println(answer);
		
	}

}