#include <bits/stdc++.h>
using namespace std;
int n, i, maxx, z, x, k, v[10005];
int main()
{
ifstream f("smartphone.in");
ofstream g("smartphone.out");
f >> k >> n;
for(i = 1; i <= n; i ++)
{
f >> v[i];
if(v[i] > maxx) maxx = v[i];
}
if(k == 1) { g << maxx; return 0; }
for(i = 1; i <= n; i ++)
{
if(v[i] != maxx && v[i] > z) z = v[i];
}
if(k == 2) g << z;
f.close();
g.close();
return 0;
}