import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class Test1 {
    public static void main(String[]args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), k = in.nextInt();
        Integer a[] = new Integer[n];

        for(int i = 0; i<n; i++)
            a[i] = new Integer(in.nextInt());
        Arrays.sort(a);

        System.out.print(k>=2?a[n-1]:a[0]);
    }
}