#include <bits/stdc++.h>

using namespace std;

int ej1(int a[], int n, int q)
{
    if (q == 1) return *min_element(a, a+n);
    if (q == 2) return max(a[0], a[n-1]);
    return *max_element(a, a+n);
}

int main()
{
    int N, Q;
    cin >> N >> Q;

    int arr[N];
    for (int i = 0; i < N; ++i)
      cin >> arr[i];

    sort(arr,arr+N);

    cout << ej1(arr, N, Q);
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n,k,a[100000+5];
	cin>>n>>k;
	int maxx=-0x3f3f3f3f,minn=0x3f3f3f3f;
	for(int i=0;i<n;i++){
		cin>>a[i];
		maxx=max(a[i],maxx);
		minn=min(a[i],minn);
	}
	if(k==1) cout<<minn<<endl;
	else if(k==2) cout<<max(a[0],a[n-1])<<endl;
	else cout<<maxx<<endl;
	return 0;
}


#include <bits/stdc++.h>

int MAX = INT_MIN, MIN=INT_MAX;

using namespace std;

int main() {
	int n, q, a[100000+5];

	cin>>n>>q;

	for(int i=0; i < n ;i++) {
		cin>>a[i];
		MAX = max(a[i],MAX);
		MIN = min(a[i],MIN);
	}

	if (q == 1) cout<< MIN <<endl;
	else cout<< MAX <<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int main() {
	int n, q, a[100000+5];

	cin>>n>>q;
	int MAX =-0x3f3f3f3f, MIN=0x3f3f3f3f;
	for(int i=0; i < n ;i++) {
		cin>>a[i];
		MAX = max(a[i],MAX);
		MIN = min(a[i],MIN);
	}
  sort(a,a+n);
	if (q == 1) cout<< MIN <<endl;
	else if (q == 2) cout<< max(a[0], a[n-1]) <<endl;
	else cout<< MAX <<endl;
	return 0;
}


#include <cstdio>
#include <queue>
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <functional>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <iomanip>
#include <limits>
#include <unordered_map>
#include <set>
#include <cmath>
#include <numeric> //accumulate
#include <stack>
#include <bitset>

//#include <unordered_set>//unordered_set

#define rep(i,a) for (int i = 0; i < (a); ++i)
#define rep2(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define PI 3.14159265359;

using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<int, pair<int, int>>> vpiii;
typedef vector<vector<int>> vvi;
typedef const vector<int> cvi;
typedef vector<bool> vb;

const ll INF = 1ull << 62;
//const int INF = 1987654321;
//const int INF = 2147483647;	// 문제에서 숫자 범위확인이 중요하다 !!!!

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	//freopen("input.txt", "r", stdin);
	int n, k; cin >> n >> k;
	ll mi = INF, mx = -INF;
	vll arr(n);
	rep(i, n) {
		ll a; cin >> a;
		if (mi > a) mi = a;
		if (mx < a) mx = a;
		arr[i] = a;
	}
	if (k == 1) cout << mi;
	else if (k >= 3) cout << mx;
	else if (arr[0] == mx || arr.back() == mx) cout << mx;
	else {
		int baseIdx = -1;
		rep(i, n) if (arr[i] == mx) {
			baseIdx = i;
		}
		ll mi1 = INF;
		ll mi2 = INF;
		for (int i = 0; i < baseIdx; ++i)
			mi1 = min(mi1, arr[i]);
		for (int i = baseIdx; i < n; ++i)
			mi2 = min(mi2, arr[i]);
		cout << max(mi1, mi2);
	}

	return 0;
}


#include <cstdio>
#include <queue>
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <functional>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <iomanip>
#include <limits>
#include <unordered_map>
#include <set>
#include <cmath>
#include <numeric> //accumulate
#include <stack>
#include <bitset>

//#include <unordered_set>//unordered_set

#define rep(i,a) for (int i = 0; i < (a); ++i)
#define rep2(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define PI 3.14159265359;

using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<int, pair<int, int>>> vpiii;
typedef vector<vector<int>> vvi;
typedef const vector<int> cvi;
typedef vector<bool> vb;

const ll INF = 1ull << 62;
//const int INF = 1987654321;
//const int INF = 2147483647;	// 문제에서 숫자 범위확인이 중요하다 !!!!

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	//freopen("input.txt", "r", stdin);
	int n, k; cin >> n >> k;
	ll mi = INF, mx = -INF;
	vll arr(n);
	rep(i, n) {
		ll a; cin >> a;
		if (mi > a) mi = a;
		if (mx < a) mx = a;
		arr[i] = a;
	}
	if (k == 1) cout << mi;
	else if (k >= 3) cout << mx;
	//else if (arr[0] == mx || arr.back() == mx) cout << mx;
	else {
		int baseIdx = -1;
		rep(i, n) if (arr[i] == mx) {
			baseIdx = i;
		}
		if (baseIdx == 0) baseIdx++;
		ll mi1 = INF;
		ll mi2 = INF;
		for (int i = 0; i < baseIdx; ++i)
			mi1 = min(mi1, arr[i]);
		for (int i = baseIdx; i < n; ++i)
			mi2 = min(mi2, arr[i]);
		cout << max(mi1, mi2);
	}

	return 0;
}


#include <cstdio>
#include <queue>
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <functional>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <iomanip>
#include <limits>
#include <unordered_map>
#include <set>
#include <cmath>
#include <numeric> //accumulate
#include <stack>
#include <bitset>

//#include <unordered_set>//unordered_set

#define rep(i,a) for (int i = 0; i < (a); ++i)
#define rep2(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define PI 3.14159265359;

using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<int, pair<int, int>>> vpiii;
typedef vector<vector<int>> vvi;
typedef const vector<int> cvi;
typedef vector<bool> vb;

const ll INF = 1ull << 62;
//const int INF = 1987654321;
//const int INF = 2147483647;	// 문제에서 숫자 범위확인이 중요하다 !!!!

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	//freopen("input.txt", "r", stdin);
	int n, k; cin >> n >> k;
	ll mi = INF, mx = -INF;
	vll arr(n);
	rep(i, n) {
		ll a; cin >> a;
		if (mi > a) mi = a;
		if (mx < a) mx = a;
		arr[i] = a;
	}
	if (k == 1) cout << mi;
	else if (k >= 3) cout << mx;
	else {
		int baseIdx = -1;
		rep(i, n) if (arr[i] == mx) {
			baseIdx = i;
		}
		ll mi1 = INF;
		ll mi2 = INF;
		for (int i = 0; i < baseIdx; ++i)
			mi1 = min(mi1, arr[i]);
		for (int i = baseIdx; i < n; ++i)
			mi2 = min(mi2, arr[i]);
		cout << max(mi1, mi2);
	}

	return 0;
}


#include <cstdio>
#include <queue>
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <functional>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <iomanip>
#include <limits>
#include <unordered_map>
#include <set>
#include <cmath>
#include <numeric> //accumulate
#include <stack>
#include <bitset>

//#include <unordered_set>//unordered_set

#define rep(i,a) for (int i = 0; i < (a); ++i)
#define rep2(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define PI 3.14159265359;

using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<int, pair<int, int>>> vpiii;
typedef vector<vector<int>> vvi;
typedef const vector<int> cvi;
typedef vector<bool> vb;

//const ll INF = 1ull << 61;
//const int INF = 1987654321;
//const int INF = 2147483647;	// 문제에서 숫자 범위확인이 중요하다 !!!!
//const int INF = 1587654321;
const int INF	= 987654321;

//5 2				// n개가 주어지고 k개로 분리할때  n and k (1 ≤ k ≤ n ≤  10^5)
//1 2 3 4 5		// 그 분리된 각각의 그룹의 최소값에 대한 최대값을 구하라.
//				// ( - 10^9  ≤  ai ≤  10^9).
//
//	k가 1인 경우 minimum 출력
//	k가 3이상인 경우 maximum 출력
//	"문제는 k가 2인 경우 순회해야 한다!!!" 생각은 했는데 단순한걸로 풀수 있겠지 하고 다른 방식으로 제출했다 망함.
//	처음 생각
//	arr[0], arr[1], arr[2], arr[3], ...
//	multiset<int> s1, s2;
//s1.insert(arr[0])
//
//s2.insert(... 나머지 전부)
//
//sol = max(s1의 최소, s2의 최소)
//for (int i = 1; i < n - 1; ++i) {
//	s1.insert(arr[i]);
//	s2.erase(arr[i]);
//	int cand = max(s1의 최소, s2의 최소);
//	sol = max(sol, cand);
//}
//
//
//굳이 집합을 쓰지 않아도 된다. // 긴장을 풀고 합시다..

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	//freopen("input.txt", "r", stdin);
	int n, k;
	cin >> n >> k;
	vi arr(n);
	rep(i, n) cin >> arr[i];
	if (k == 1)
		cout << *min_element(arr.begin(), arr.end());
	else if (k >= 3)
		cout << *max_element(arr.begin(), arr.end());
	else if (k == 2) {
		vi s1(n, INF), s2(n, INF);
		s1[0] = arr[0];
		for (int i = 1; i < n; ++i)
			s1[i] = min(arr[i], s1[i - 1]);	// 시작부터 i까지의 구간 최소값
		s2[n - 1] = arr[n - 1];
		for (int i = n - 1 - 1; i >= 0; --i)
			s2[i] = min(arr[i], s2[i + 1]);	// 끝부터 i까지의 구간 최소값

		int sol = max(s1[0], s2[1]);
		for (int i = 1; i < n - 1; ++i) {
			int cand = max(s1[i], s2[i + 1]);
			sol = max(sol, cand);
		}
		cout << sol;
	}
	return 0;
}


#include <cstdio>
#include <queue>
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <functional>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <iomanip>
#include <limits>
#include <unordered_map>
#include <set>
#include <cmath>
#include <numeric> //accumulate
#include <stack>
#include <bitset>

//#include <unordered_set>//unordered_set

#define rep(i,a) for (int i = 0; i < (a); ++i)
#define rep2(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define PI 3.14159265359;

using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<int, pair<int, int>>> vpiii;
typedef vector<vector<int>> vvi;
typedef const vector<int> cvi;
typedef vector<bool> vb;

const ll INF = 1ull << 62;
//const int INF = 1987654321;
//const int INF = 2147483647;	// 문제에서 숫자 범위확인이 중요하다 !!!!

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	//freopen("input.txt", "r", stdin);
	int n, k; cin >> n >> k;
	ll mi = INF, mx = -INF;
	rep(i, n) {
		ll a; cin >> a;
		if (mi > a) mi = a;
		if (mx < a) mx = a;
	}
	if (k == 1) cout << mi;
	else cout << mx;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n, k, a[100010];
int main () {
	scanf ("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) scanf ("%d", &a[i]);
	int minn = a[1], max = a[1];
	for (int i = 1; i <= n; i++) minn = min (minn, a[i]), maxn = max (maxn, a[i]);
	if (k == 1) printf ("%d\n", minn);
	else printf ("%d\n", maxn);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n, k, a[100010], mi[100010], ma[100010];
int main () {
	scanf ("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) scanf ("%d", &a[i]);
	int minn = a[1], maxn = a[1];
	for (int i = 1; i <= n; i++) minn = min (minn, a[i]), maxn = max (maxn, a[i]);
	if (k == 1) printf ("%d\n", minn);
	else if (k == 2) printf ("%d\n", max (a[1], a[n]));
	else printf ("%d\n", maxn);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n, k, a[100010];
int main () {
	scanf ("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) scanf ("%d", &a[i]);
	int minn = a[1], maxn = a[1];
	for (int i = 1; i <= n; i++) minn = min (minn, a[i]), maxn = max (maxn, a[i]);
	if (k == 1) printf ("%d\n", minn);
	else printf ("%d\n", maxn);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n, k, a[100010], mi[100010], ma[100010];
int main () {
	scanf ("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) scanf ("%d", &a[i]);
	int minn = a[1], maxn = a[1];
	for (int i = 1; i <= n; i++) minn = min (minn, a[i]), maxn = max (maxn, a[i]);
	if (k == 1) printf ("%d\n", minn);
	else if (k == 2) {
		mi[1] = a[1], ma[n] = a[n];
		for (int i = 2; i <= n; i++) mi[i] = min (mi[i - 1], a[i]);
		for (int i = n - 1; i > 1; i--) ma[i] = min (ma[i + 1], a[i]);
		int ans = 0;
		for (int i = 1; i < n; i++) ans = max (ans, max (mi[i], ma[i + 1]));
		printf ("%d\n", ans);
	}
	else printf ("%d\n", maxn);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,a[100005],mn=1000000001,mx=-1000000001,i,ans;
    cin>>n>>m;
    for(i=0;i<n;i++){
        cin>>a[i];
    mn=min(mn,a[i]);
    mx=max(mx,a[i]);
    }
    //sort(a,a+n);
    if(m==1)cout<<mn<<endl;
    else if(m==2){

            ans=max(a[0],a[n-1]);
            cout<<ans<<endl;
    }
    else cout<<mx<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,a[100005],mn=1000000001,mx=-1000000001,i;
    cin>>n>>m;
    for(i=0;i<n;i++){
        cin>>a[i];
        mn=min(mn,a[i]);
        mx=max(mx,a[i]);
    }
    if(m==1)cout<<mn<<endl;
    else cout<<mx<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,a,mn=1000000001,mx=-1000000001,i;
    cin>>n>>m;
    for(i=0;i<n;i++){
        cin>>a;
    mn=min(mn,a);
    mx=max(mx,a);
    }
    //sort(a,a+n);
    if(m==1)cout<<mn<<endl;
    else cout<<mx<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,a[100005],mn=1000000001,mx=-1000000001,i;
    cin>>n>>m;
    for(i=0;i<n;i++){
cin>>a[i];
    }
    sort(a,a+n);
    if(m==1)cout<<a[0]<<endl;
    else cout<<a[n-1]<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, k;
	cin>> n>>k;
	int ar[n];
	int mx=-INT_MAX, mn=INT_MAX;
	for(int i=0; i<n; i++){
		cin>> ar[i];
		mx=max(ar[i], mx);
		mn=min(ar[i], mn);
	}
	if(k==1){
		cout<<mn;
		return 0;
	}
	if(k>=3){
		cout<< mx;
		return 0;
	}
	else{
		int mar[n];
		mar[n-1]=ar[n-1];
		for(int i=n-2; i>0; i--){
			mar[i]=min(mar[i+1], ar[i]);
		}
		int mmn=ar[0];
		int ans=-INT_MAX;
		for(int i=0; i<n-1; i++){
			mmn=(mmn, ar[i]);
			int ans1=max(mar[i+1], mmn);
			ans=max(ans, ans1);
		}
		cout<< ans;
		return 0;
	}
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, k;
	cin>> n>>k;
	int ar[n];
	int mx=0, mn=INT_MAX;
	for(int i=0; i<n; i++){
		mx=max(ar[i], mx);
		mn=min(ar[i], mn);
	}
	if(k==1){
		cout<<mn;
		return 0;
	}
	if(k>=3){
		cout<< mx;
		return 0;
	}
	else{
		int mar[n];
		mar[n-1]=ar[n-1];
		for(int i=n-2; i>0; i--){
			mar[i]=min(mar[i+1], ar[i]);
		}
		int mmn=ar[0];
		int ans=0;
		for(int i=0; i<n-1; i++){
			mmn=(mmn, ar[i]);
			ans=max(mar[i+1], mmn);
		}
		cout<< ans;
		return 0;
	}
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, k;
	cin>> n>>k;
	int ar[n];
	int mx=0, mn=INT_MAX;
	for(int i=0; i<n; i++){
		cin>> ar[i];
		mx=max(ar[i], mx);
		mn=min(ar[i], mn);
	}
	if(k==1){
		cout<<mn;
		return 0;
	}
	if(k>=3){
		cout<< mx;
		return 0;
	}
	else{
		int mar[n];
		mar[n-1]=ar[n-1];
		for(int i=n-2; i>0; i--){
			mar[i]=min(mar[i+1], ar[i]);
		}
		int mmn=ar[0];
		int ans=0;
		for(int i=0; i<n-1; i++){
			mmn=(mmn, ar[i]);
			ans=max(mar[i+1], mmn);
		}
		cout<< ans;
		return 0;
	}
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, k;
	cin>> n>>k;
	int ar[n];
	int mx=-INT_MAX, mn=INT_MAX;
	for(int i=0; i<n; i++){
		cin>> ar[i];
		mx=max(ar[i], mx);
		mn=min(ar[i], mn);
	}
	if(k==1){
		cout<<mn;
		return 0;
	}
	if(k>=3){
		cout<< mx;
		return 0;
	}
	else{
		int mar[n];
		mar[n-1]=ar[n-1];
		for(int i=n-2; i>0; i--){
			mar[i]=min(mar[i+1], ar[i]);
		}
		int mmn=ar[0];
		int ans=-INT_MAX;
		for(int i=0; i<n-1; i++){
			mmn=min(mmn, ar[i]);
			int ans1=max(mar[i+1], mmn);
			ans=max(ans, ans1);
		}
		cout<< ans;
		return 0;
	}
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, k;
	cin>> n>>k;
	int ar[n];
	int mx=0, mn=INT_MAX;
	for(int i=0; i<n; i++){
		cin>> ar[i];
		mx=max(ar[i], mx);
		mn=min(ar[i], mn);
	}
	if(k==1){
		cout<<mn;
		return 0;
	}
	if(k>=3){
		cout<< mx;
		return 0;
	}
	else{
		int mar[n];
		mar[n-1]=ar[n-1];
		for(int i=n-2; i>0; i--){
			mar[i]=min(mar[i+1], ar[i]);
		}
		int mmn=ar[0];
		int ans=0;
		for(int i=0; i<n-1; i++){
			mmn=(mmn, ar[i]);
			int ans1=max(mar[i+1], mmn);
			ans=max(ans, ans1);
		}
		cout<< ans;
		return 0;
	}
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second

using namespace std;

const double pi=acos(-1);
const int N=(int)1e6+7,mod=1000000007,M=2e9;

//scanf("%d",&);
int n,k,arr[N];

int main()
{
//    freopen(".txt","r",stdin);
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>arr[i];
    sort(arr,arr+n);
    if(k==1)cout<<arr[0];
    else cout<<arr[n-1];
    return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second

using namespace std;

const double pi=acos(-1);
const int N=(int)1e6+7,mod=1000000007,M=2e9;

//scanf("%d",&);
ll n,k,t,mn=1000000007,mx=-1000000007;

int main()
{
//    freopen(".txt","r",stdin);
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>t;
        mn=min(mn,t);
        mx=max(mx,t);
    }
    if(k==1)cout<<mn;
    else cout<<mx;
    return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second

using namespace std;

const double pi=acos(-1);
const int N=(int)1e6+7,mod=1000000007,M=2e9;

//scanf("%d",&);
ll n,k,arr[N],mn=10000000007,mx=-10000000007;

int main()
{
//    freopen(".txt","r",stdin);
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        mn=min(mn,arr[i]);
        mx=max(mx,arr[i]);
    }
    if(k==2)cout<<max(arr[0],arr[n-1]);
    else if(k==1)cout<<mn;
    else cout<<mx;
    return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second

using namespace std;

const double pi=acos(-1);
const int N=(int)1e6+7,mod=1000000007,M=2e9;

//scanf("%d",&);
ll n,k,t,mn=M,mx=-M;

int main()
{
//    freopen(".txt","r",stdin);
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>t;
        mn=min(mn,t);
        mx=max(mx,t);
    }
    if(k==1)cout<<mn;
    else cout<<mx;
    return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second

using namespace std;

const double pi=acos(-1);
const int N=(int)1e6+7,mod=1000000007,M=2e9;

//scanf("%d",&);
ll n,k,t,mn=10000000007,mx=-10000000007;

int main()
{
//    freopen(".txt","r",stdin);
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>t;
        mn=min(mn,t);
        mx=max(mx,t);
    }
    if(k==1)cout<<mn;
    else cout<<mx;
    return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second

using namespace std;

const double pi=acos(-1);
const int N=(int)1e6+7,mod=1000000007,M=1e9+7;

//scanf("%d",&);
int n,k,t,mn=M,mx=-M;

int main()
{
//    freopen(".txt","r",stdin);
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>t;
        mn=min(mn,t);
        mx=max(mx,t);
    }
    if(k==1)cout<<mn;
    else cout<<mx;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+100;
const int inf = 1e9+10;
int a[maxn];
int main(void)
{
    int n,k;
    scanf("%d %d",&n,&k);
    int ma = -inf,t1;
    int mi = inf;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        mi = min(mi,a[i]);
        if(a[i]>ma)
        {
            ma = a[i];
            t1 = i;
        }
    }
    if(k==1)
        printf("%d\n",mi);
    else if(k>2 || t1==0 || t1==n-1)
        printf("%d\n",ma);
    else
    {
        int m1 = t1,m2 = t1;
        for(int i=0;i<t1;i++)
            m1 = min(m1,a[i]);
        for(int i=t1+1;i<n;i++)
            m2 = min(m2,a[i]);
        printf("%d\n",max(m1,m2));
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+100;
const int inf = 1e9+10;
int a[maxn];
int main(void)
{
    int n,k;
    scanf("%d %d",&n,&k);
    int ma = -inf,t1;
    int mi = inf;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        mi = min(mi,a[i]);
        if(a[i]>ma)
        {
            ma = a[i];
            t1 = i;
        }
    }
    if(k==1)
        printf("%d\n",mi);
    else if(k>2 || t1==0 || t1==n-1)
        printf("%d\n",ma);
    else
    {
        int m1 = t1,m2 = t1;
        for(int i=0;i<t1;i++)
            m1 = min(m1,a[i]);
        for(int i=t1;i<n;i++)
            m2 = min(m2,a[i]);
        printf("%d\n",max(m1,m2));
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+100;
const int inf = 1e9+10;
int a[maxn];
int main(void)
{
    int n,k;
    scanf("%d %d",&n,&k);
    int ma = -inf,t1;
    int mi = inf;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        mi = min(mi,a[i]);
        if(a[i]>ma)
        {
            ma = a[i];
            t1 = i;
        }
    }
    if(k==1)
        printf("%d\n",mi);
    else if(k>2)
        printf("%d\n",ma);
    else
    {
        int m1 = inf,m2 = inf;
        for(int i=0;i<t1;i++)
            m1 = min(m1,a[i]);
        for(int i=t1;i<n;i++)
            m2 = min(m2,a[i]);
        printf("%d\n",max(m1,m2));
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+100;
const int inf = 1e9+10;
int a[maxn];
int main(void)
{
    int n,k;
    scanf("%d %d",&n,&k);
    int ma = -inf,t1;
    int mi = inf;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        mi = min(mi,a[i]);
        if(a[i]>ma)
        {
            ma = a[i];
            t1 = i;
        }
    }
    if(k==1)
        printf("%d\n",mi);
    else if(k>2 || t1==0 || t1==n-1)
        printf("%d\n",ma);
    else
    {
        int m1 = ma,m2 = ma;
        for(int i=0;i<t1;i++)
            m1 = min(m1,a[i]);
        for(int i=t1+1;i<n;i++)
            m2 = min(m2,a[i]);
        printf("%d\n",max(m1,m2));
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+100;
const int inf = 1e9+10;
int a[maxn];
int main(void)
{
    int n,k;
    scanf("%d %d",&n,&k);
    int ma = -inf;
    int mi = inf;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        mi = min(mi,a[i]);
        ma = max(ma,a[i]);
    }
    if(k==1)
        printf("%d\n",mi);
    else if(k>2)
        printf("%d\n",ma);
    else
        printf("%d\n",max(a[0],a[n-1]));
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n, k; cin >> n >> k;
	int arr[n];
	int mx = -1;
	int ind = -1;
	int q = 1000000;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> arr[i];
		mx = max(mx, arr[i]);
		if (mx == arr[i]) ind = i;
		q = min(q, arr[i]);
	}if (k == 1) cout << q;
	else if (k >= 3 || ind == n - 1 || ind == 0) cout << mx << endl;
	else {
		int mn, lmn;
	mn = lmn = 100000000;
		for (int i = ind + 1; i < n; i++) {
			mn = min(mn, arr[i]);
		}
		for (int i = ind - 1; i >= 0; i--) {
			lmn = min(lmn , arr[i]);
		}
		cout << max(lmn, mn);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n, k; cin >> n >> k;
	int arr[n];
	int mx = -1;
	int ind = -1;
	int q = 1000000;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> arr[i];
		mx = max(mx, arr[i]);
		if (mx == arr[i]) ind = i;
		q = min(q, arr[i]);
	}if (k == 1) cout << q;
	else if (k >= 3 || ind == n - 1 || ind == 0) cout << mx << endl;
	else {
		cout << max(arr[0], arr[n-1]);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define int ll
int32_t main() {
	int n, k; cin >> n >> k;
	int arr[n];
	int mx = -10000000000;
	int ind = -10000000000;
	int q = 1e10;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> arr[i];
		mx = max(mx, arr[i]);
		if (mx == arr[i]) ind = i;
		q = min(q, arr[i]);
	}if (k == 1) cout << q;
	else if (k >= 3 || ind == n - 1 || ind == 0) cout << mx << endl;
	else {
		cout << max(arr[0], arr[n-1]);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define int ll
int32_t main() {
	int n, k; cin >> n >> k;
	int arr[n];
	int mx = -1;
	int ind = -1;
	int q = 1000000;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> arr[i];
		mx = max(mx, arr[i]);
		if (mx == arr[i]) ind = i;
		q = min(q, arr[i]);
	}if (k == 1) cout << q;
	else if (k >= 3 || ind == n - 1 || ind == 0) cout << mx << endl;
	else {
		cout << max(arr[0], arr[n-1]);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define int ll
int32_t main() {
	int n, k; cin >> n >> k;
	int arr[n];
	int mx = -1;
	int ind = -1;
	int q = 1e10;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> arr[i];
		mx = max(mx, arr[i]);
		if (mx == arr[i]) ind = i;
		q = min(q, arr[i]);
	}if (k == 1) cout << q;
	else if (k >= 3 || ind == n - 1 || ind == 0) cout << mx << endl;
	else {
		cout << max(arr[0], arr[n-1]);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll al[100005];
int main()
{
    long long n,m;
    while(cin>>n>>m)
    {
        ll arr[100005],N[100005];
        ll x=100000005;
        //int pos;
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
            N[i]=arr[i];
            //cout<<x<<endl;
            if(x>=arr[i])
            {
                x=arr[i];
                al[i]=x;
            }
            else
            {
                al[i]=x;
            }
        }
        sort(arr,arr+n);
        ll mx=arr[n-1];

        if(m==1)
        {
            cout<<arr[0]<<endl;
        }
        else if(m==2 && (N[n-1]==arr[n-1] || N[0]==arr[n-1]))
        {
            cout<<arr[n-1]<<endl;
        }
        else if(m==2 )
        {
            ll ans;
            for(int i=0;i<n;i++)
            {
                if(N[i]==mx)
                {
                    //cout<<al[n-1]<<' '<<al[i-1]<<endl;
                    ans=max(al[i-1],al[n-1]);
                }
            }
            cout<<ans<<endl;
        }
        else if(m>=3)
        {
            cout<<arr[n-1]<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//ll al[100005];
int main()
{
    long long n,m;
    while(cin>>n>>m)
    {
        ll arr[100005],N[100005];
        //ll x=100000005;
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
            N[i]=arr[i];
        }
        sort(arr,arr+n);
        ll mx=arr[n-1];

        if(m==1)
        {
            cout<<arr[0]<<endl;
        }
        else if(m==2 && (N[n-1]==arr[n-1] || N[0]==arr[n-1]))
        {
            cout<<arr[n-1]<<endl;
        }
        else if(m==2 )
        {
            ll ans;
            ll mn=100000005;
            //ll mnn=1000000005;
            vector<ll> haha;
            for(int i=0;i<n;i++)
            {
                mn=min(mn,N[i]);
                if(N[i]==mx)
                {
                    haha.push_back(mn);
                    mn=100000005;
                }
            }
            haha.push_back(mn);
            sort(haha.begin(),haha.end());
            cout<<haha[haha.size()-1]<<endl;
        }
        else if(m>=3)
        {
            cout<<arr[n-1]<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    long long n,m;
    while(cin>>n>>m)
    {
        ll arr[100005],N[100005];
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
            N[i]=arr[i];
        }
        sort(arr,arr+n);
        if(m==1)
        {
            cout<<arr[0]<<endl;
        }
        else if(m==2 && (N[n-1]==arr[n-1] || N[0]==arr[n-1]))
        {
            cout<<arr[n-1]<<endl;
        }
        else if(m==2 )
        {
            cout<<arr[1]<<endl;
        }
        else if(m>=3)
        {
            cout<<arr[n-1]<<endl;
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//ll al[100005];
int main()
{
    long long n,m;
    while(cin>>n>>m)
    {
        ll arr[100005],N[100005];
        //ll x=100000005;
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
            N[i]=arr[i];
        }
        sort(arr,arr+n);
        ll mx=arr[n-1];

        if(m==1)
        {
            cout<<arr[0]<<endl;
        }
        else if(m==2 && (N[n-1]==arr[n-1] || N[0]==arr[n-1]))
        {
            cout<<arr[n-1]<<endl;
        }
        else if(m==2 )
        {
            cout<<max(N[0],N[n-1])<<endl;
        }
        else if(m>=3)
        {
            cout<<arr[n-1]<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcountll
#define INF 1e18
#define endl '\n'
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" |\
									 "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" |\
									 "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" |\
									 "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<< c<<" |\
								 "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

using namespace std;

const int N = 1e5+10;
const int M = 1e9+7;
int a[N], b[N];
int main(){
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		b[i] = a[i];
	}
	int x = a[0]; int y = a[n-1];
	sort(a,a+n);
	if(n == 1){
		cout << a[0];
		return 0;
	}
	if(k == 1){
		cout << a[0];
		return 0;
	}
	if(k == 2){
		multiset <int> s;
		for(int i = 0; i < n; ++i){
			s.insert(b[i]);
		}
		int mn = b[0];
		int ans = -1;
		for(int i = 0; i < n-1; ++i){
			mn = min(b[i],mn);
			auto it = s.find(a[i]);
			s.erase(it);
			ans = max(mn, *s.begin());
		}
		cout << ans;
		return 0;
	}
	cout << a[n-1];
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcountll
#define INF 1e18
#define endl '\n'
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" |\
									 "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" |\
									 "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" |\
									 "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<< c<<" |\
								 "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

using namespace std;

const int N = 1e5+10;
const int M = 1e9+7;
int a[N], b[N];
int main(){
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		b[i] = a[i];
	}
	int x = a[0]; int y = a[n-1];
	sort(a,a+n);
	if(n == 1){
		cout << a[0];
		return 0;
	}
	if(k == 1){
		cout << a[0];
		return 0;
	}
	if(k == 2){
		multiset <int> s;
		for(int i = 0; i < n; ++i){
			s.insert(b[i]);
		}
		int mn = b[0];
		int ans = -1;
		for(int i = 0; i < n-1; ++i){
			mn = min(b[i],mn);
			auto it = s.find(b[i]);
			s.erase(it);
			ans = max(mn, *s.begin());
		}
		cout << ans;
		return 0;
	}
	cout << a[n-1];
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcountll
#define INF 1e18
#define endl '\n'
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" |\
									 "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" |\
									 "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" |\
									 "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<< c<<" |\
								 "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

using namespace std;

const int N = 1e5+10;
const int M = 1e9+7;
int a[N];
int main(){
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	int x = a[0]; int y = a[n-1];
	sort(a,a+n);
	if(n == 1){
		cout << a[0];
		return 0;
	}
	if(k == 1){
		cout << a[0];
		return 0;
	}
	if(k == 2){
		multiset <int> s;
		for(int i = 0; i < n; ++i){
			s.insert(a[i]);
		}
		int mn = a[0];
		int ans = -1;
		for(int i = 0; i < n-1; ++i){
			mn = min(a[0],mn);
			auto it = s.find(a[i]);
			s.erase(it);
			ans = max(a[i], *s.begin());
		}
		cout << ans;
		return 0;
	}
	cout << a[n-1];
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcountll
#define INF 1e18
#define endl '\n'
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" |\
									 "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" |\
									 "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" |\
									 "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<< c<<" |\
								 "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

using namespace std;

const int N = 1e5+10;
const int M = 1e9+7;
int a[N];
int main(){
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	int x = a[0]; int y = a[n-1];
	sort(a,a+n);
	if(n == 1){
		cout << a[0];
		return 0;
	}
	if(k == 1){
		cout << a[0];
		return 0;
	}
	if(k == 2){
		multiset <int> s;
		for(int i = 0; i < n; ++i){
			s.insert(a[i]);
		}
		int mn = a[0];
		int ans = -1;
		for(int i = 0; i < n-1; ++i){
			mn = min(a[i],mn);
			auto it = s.find(a[i]);
			s.erase(it);
			ans = max(mn, *s.begin());
		}
		cout << ans;
		return 0;
	}
	cout << a[n-1];
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcountll
#define INF 1e18
#define endl '\n'
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" |\
									 "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" |\
									 "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" |\
									 "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<< c<<" |\
								 "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

using namespace std;

const int N = 1e5+10;
const int M = 1e9+7;
int a[N], b[N];
int main(){
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		b[i] = a[i];
	}
	int x = a[0]; int y = a[n-1];
	sort(a,a+n);
	if(n == 1){
		cout << a[0];
		return 0;
	}
	if(k == 1){
		cout << a[0];
		return 0;
	}
	if(k == 2){
		multiset <int> s;
		for(int i = 0; i < n; ++i){
			s.insert(b[i]);
		}
		int mn = b[0];
		int ans = -1e9-10;
		for(int i = 0; i < n-1; ++i){
			mn = min(b[i],mn);
			auto it = s.find(b[i]);
			s.erase(it);
			ans = max(ans, *s.begin());
			ans = max(ans, mn);
		}
		cout << ans;
		return 0;
	}
	cout << a[n-1];
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcountll
#define INF 1e18
#define endl '\n'
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" |\
									 "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" |\
									 "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" |\
									 "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<< c<<" |\
								 "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

using namespace std;

const int N = 1e5+10;
const int M = 1e9+7;
int a[N], b[N];
int main(){
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		b[i] = a[i];
	}
	int x = a[0]; int y = a[n-1];
	sort(a,a+n);
	if(n == 1){
		cout << a[0];
		return 0;
	}
	if(k == 1){
		cout << a[0];
		return 0;
	}
	if(k == 2){
		multiset <int> s;
		for(int i = 0; i < n; ++i){
			s.insert(b[i]);
		}
		int mn = b[0];
		int ans = -1;
		for(int i = 0; i < n-1; ++i){
			mn = min(b[i],mn);
			auto it = s.find(b[i]);
			s.erase(it);
			ans = max(ans, *s.begin());
			ans = max(ans, mn);
		}
		cout << ans;
		return 0;
	}
	cout << a[n-1];
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcountll
#define INF 1e18
#define endl '\n'
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" |\
									 "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" |\
									 "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" |\
									 "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<< c<<" |\
								 "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

using namespace std;

const int N = 1e5+10;
const int M = 1e9+7;
int a[N];
int main(){
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	int x = a[0]; int y = a[n-1];
	sort(a,a+n);
	if(n == 1){
		cout << a[0];
		return 0;
	}
	if(k == 1){
		cout << a[0];
		return 0;
	}
	if(k == 2){
		multiset <int> s;
		for(int i = 0; i < n; ++i){
			s.insert(a[i]);
		}
		int mn = a[0];
		int ans = -1;
		for(int i = 0; i < n-1; ++i){
			mn = min(a[0],mn);
			auto it = s.find(a[i]);
			s.erase(it);
			ans = max(mn, *s.begin());
		}
		cout << ans;
		return 0;
	}
	cout << a[n-1];
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr first
#define sc second
#define r_0 return 0
using namespace std;

const ll N = 1e5 + 1 ;

ll n , m , k , l , x , y  , z , cnt , ans , sum , mn = 1e18 , mx = -1e18 ;

string s , t ;
int a[17] ;

int main(){
    //freopen( "input.txt", "r" , stdin );
    //freopen( "output.txt", "w" , stdout );
    ios_base::sync_with_stdio(0);
    cin >> n ;
    for ( int i =1 ; i <= n ; i++ )
        cin >> a[i];
    //
    x = n ;
    cnt = 1 ;
    for ( int i = 1; i <= n ;i ++ )
    {
        if ( a[i] <= a[i + 1] )
            cnt ++ ;
    }
    if ( cnt == n )
    {
        cout << cnt ;
        r_0;
    }
    n /= 2 ;
    cnt = 1 ;
    for ( int i = 1 ; i < n ; i ++ ){
        if ( a[i] <= a[i + 1] )
            cnt ++ ;
    }
    if ( cnt == n )
    {
        cout << cnt ;
        r_0;
    }
    cnt = 1;
    for ( int i = n + 1; i < x ; i ++ )
    {
        if ( a[i] <= a[i + 1] )
            cnt ++ ;
    }
    if ( cnt == n )
    {
        cout<< cnt ;
        r_0;
    }
    n /= 2 ;

    x /= 2 ;cnt = 1;
    for ( int i = 1; i < n ; i ++ )
    {
        if ( a[i] <= a[ i + 1] )
            cnt ++ ;
    }
    if ( cnt == n )
    {
        cout << n ;
        r_0;
    }
    cnt = 1;
    for ( int i = n + 1 ; i < x ; i ++ )
    {
        if ( a[i] <= a[i + 1] )
            cnt ++ ;
    }
    if  ( cnt == n )
    {
        cout << cnt ;
        r_0;
    }
    x += n ;
    n += 4 ;
    cnt = 1 ;
    for ( int i = n + 1; i < x ; i ++ )
    {
        if ( a[i] <= a[i + 1] )
            cnt ++ ;
    }
    if ( cnt == 4 )
    {
        cout << cnt ;
        r_0;
    }
    x = 16 ;
    n = 13 ;
    cnt = 1 ;
    for ( int i = n ; i < x ; i ++ )
    {
        if ( a[i] <= a[i + 1] )
            cnt ++ ;
    }
    if ( cnt == 4 )
    {
        cout << cnt;
        r_0;
    }
    cout << 2 ;

}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr first
#define sc second
#define r_0 return 0
using namespace std;

const ll N = 1e5 + 1 ;

ll n , m , k , l , x , y  , z , cnt , ans , sum , mn = 1e18 , mx = -1e18 ;

string s , t ;
int a[17] ;

int main(){
    //freopen( "input.txt", "r" , stdin );
    //freopen( "output.txt", "w" , stdout );
    ios_base::sync_with_stdio(0);
    cin >> n ;
    for ( int i =1 ; i <= n ; i++ )
        cin >> a[i];
    if ( n == 16 ){
        for ( int i = 1; i <= n ; i ++ )
        {
            if ( a[i] == i )
                l ++ ;
        }
        if ( l == n )
        {
            cout << l ;
            r_0;
        }
    }
    x = n ;
    cnt = 1 ;
    for ( int i = 1; i <= n ;i ++ )
    {
        if ( a[i] <= a[i + 1] )
            cnt ++ ;
    }
    if ( cnt == n )
    {
        cout << cnt ;
        r_0;
    }
    n /= 2 ;
    cnt = 1 ;
    for ( int i = 1 ; i < n ; i ++ ){
        if ( a[i] <= a[i + 1] )
            cnt ++ ;
    }
    if ( cnt == n )
    {
        cout << cnt ;
        r_0;
    }
    cnt = 1;
    for ( int i = n + 1; i < x ; i ++ )
    {
        if ( a[i] <= a[i + 1] )
            cnt ++ ;
    }
    if ( cnt == n )
    {
        cout<< cnt ;
        r_0;
    }
    n /= 2 ;

    x /= 2 ;cnt = 1;
    for ( int i = 1; i < n ; i ++ )
    {
        if ( a[i] <= a[ i + 1] )
            cnt ++ ;
    }
    if ( cnt == n )
    {
        cout << n ;
        r_0;
    }
    cnt = 1;
    for ( int i = n + 1 ; i < x ; i ++ )
    {
        if ( a[i] <= a[i + 1] )
            cnt ++ ;
    }
    if  ( cnt == n )
    {
        cout << cnt ;
        r_0;
    }
    x += n ;
    n += 4 ;
    cnt = 1 ;
    for ( int i = n + 1; i < x ; i ++ )
    {
        if ( a[i] <= a[i + 1] )
            cnt ++ ;
    }
    if ( cnt == 4 )
    {
        cout << cnt ;
        r_0;
    }
    x = 16 ;
    n = 13 ;
    cnt = 1 ;
    for ( int i = n ; i < x ; i ++ )
    {
        if ( a[i] <= a[i + 1] )
            cnt ++ ;
    }
    if ( cnt == 4 )
    {
        cout << cnt;
        r_0;
    }
    cout << 2 ;

}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define sz size()
#define fr first
#define sc second
#define r return
#define TIME ios_base::sync_with_stdio( 0 );

using namespace std;

    const ll N = 1e6 + 1;
    const ll INF = 1e18 ;

ll n , m , l , k , x , y , z , cnt , ans , sum , mx , mn = INF ;
int main()
{
    TIME

    cin >> n ;
    cnt = 1;
    vector < ll > v ;
    for ( int i = 0 ; i < n ; i ++ )
        cin >> l , v.pb ( l );
    while ( n ){
        for ( ll i = 0 ; i < n - 1 ; i ++ )
        {
            if ( v[ i ] <= v [ i + 1 ] )
                cnt ++ ;
            if ( i == n - 2 ){
                if ( cnt == n ){
                   r cout << cnt , 0;
                }
            }
        }
        cnt = 1;
        n /= 2 ;
    }
    cout << 1 ;
}


#include<bits/stdc++.h>
using namespace std;
int a[100];
int f(int first,int last){
    if(is_sorted(a+first,a+last)) return last-first;
    return max(f(first,(first+last)/2),f((first+last)/2,last));
}
int main(){
    int n; cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    int b=f(0,n);
    cout<<b<<endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;

int maximal(int a[],int l,int r)
{
    int length = 1;
    for(int i=l;i<r-1;i++)
    {
        if(a[i]<=a[i+1])
        {
            length++;
        }
        else break;
    }
    return length;
}
int thanos_sort(int a[],int l,int r)
{
    int whole = maximal(a,l,r);
    if(whole == (r-l))
    return (r-l);
    int first_length = maximal(a,l,r/2);
    int second_length = maximal(a,r/2,r);
    if(second_length == (r-l)/2)
    return r/2;
    if(first_length == (r-l)/2)
    return r/2;
    if(second_length>first_length)
    {
        return thanos_sort(a,r/2,r);
    }
    else return thanos_sort(a,l,r/2);
}

int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    cout<<thanos_sort(a,0,n);
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;

int maximal(int a[],int l,int r)
{
    int length = 1;
    for(int i=l;i<r-1;i++)
    {
        if(a[i]<=a[i+1])
        {
            length++;
        }
        else break;
    }
    return length;
}
int thanos_sort(int a[],int l,int r)
{
    int whole = maximal(a,l,r);
    if(whole == (r-l))
    return (r-l);
    int first_length = maximal(a,l,r/2);
    int second_length = maximal(a,r/2,r);
    if(second_length == (r/2))
    return (r/2);
    if(first_length == (r/2-l))
    return (r/2-l);
    if(second_length>first_length)
    {
        return thanos_sort(a,r/2,r);
    }
    else return thanos_sort(a,l,r/2);
}

int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    cout<<thanos_sort(a,0,n);
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;

int maximal(int a[],int l,int r)
{
    int length = 1;
    for(int i=l;i<r-1;i++)
    {
        if(a[i]<=a[i+1])
        {
            length++;
        }
        else break;
    }
    return length;
}
int thanos_sort(int a[],int l,int r)
{

    int first_length = maximal(a,l,r/2);
    int second_length = maximal(a,r/2,r);
    if(second_length == (r/2))
    return (r/2);
    if(first_length == (r/2-l))
    return (r/2-l);
    if(second_length>first_length)
    {
        return thanos_sort(a,r/2,r);
    }
    else return thanos_sort(a,l,r/2);
}

int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    if(maximal(a,0,n)==n)
    cout<<n;
    else cout<<thanos_sort(a,0,n);
}


#include<bits/stdc++.h>
#include <iostream>
using namespace std;

int main()
{
    int n, v[100], i, j;
    cin >> n;
    for (i=0; i < n; i++)
        cin >> v[i];
    for (i = n; i > 0; i>>=1)
        for (j = 0; j < n; j =j+i)
            if (is_sorted(v + j, v + j + i))
            {
                 cout << i;
                 return 0;
            }
}


#include<bits/stdc++.h>
#include <iostream>
using namespace std;

int main()
{
    int n, v[100], i, j;
    cin >> n;
    for (i=0; i < n; i++)
        cin >> v[i];
    for (i = n; i > 0; i=i/2)
        for (j = 0; j < n; j =j+i)
            if (is_sorted(v + j, v + j + i))
            {
                cout << i;
                return 0;
            }

}


#include<bits/stdc++.h>
#include <iostream>
using namespace std;

int main()
{
    int n, v[100], i, j;
    cin >> n;
    for (i=0; i < n; i++)
        cin >> v[i];
    for (i = n; i > 0; i>>=1)
        for (j = 0; j < n; j =j+i)
            if (is_sorted(v + j, v + j + i))
                 cout << i;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,j,i;
cin>>n;
int a[n];
for(i=0;i<n;i++)
cin>>a[i];
for(i=n;i>0;i>>=1)
for(j=0;j<n;j+=i)
if(is_sorted(a+j,a+i+j))
{cout<<i;
return 0;}
}


#include<cstdio>
#include<algorithm>
using namespace std;
int n;
int a[20];
int ans=0;
void find(int l,int r){
	bool f1,f2;
	for(int i=l+1;i<=r;++i){
		if(a[i]<a[i-1]){
			f1=1;break;
		}
	}
	if(!f1){
		ans=max(ans,r-l+1);
		return;
	}
	int mid=l+r>>1;
	find(l,mid);find(mid+1,r);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
	}
	if(n==1){
		puts("1");
		return 0;
	}
	find(1,n);
	printf("%d",ans);
    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int n;
int a[20];
int ans=1;
void find(int l,int r){
	bool f1=0;
	if(l>=r)return;
	for(int i=l+1;i<=r;++i){
		if(a[i]<a[i-1]){
			f1=1;break;
		}
	}
	if(!f1){
		ans=max(ans,r-l+1);
		return;
	}
	int mid=l+r>>1;
	find(l,mid);find(mid+1,r);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
	}
	if(n==1){
		puts("1");
		return 0;
	}
	find(1,n);
	printf("%d",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int n;
int a[20];
int ans=0;
void find(int l,int r){
	bool f1,f2;
	if(l>=r)return;
	for(int i=l+1;i<=r;++i){
		if(a[i]<a[i-1]){
			f1=1;break;
		}
	}
	if(!f1){
		ans=max(ans,r-l+1);
		return;
	}
	int mid=l+r>>1;
	find(l,mid);find(mid+1,r);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
	}
	if(n==1){
		puts("1");
		return 0;
	}
	find(1,n);
	printf("%d",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int n;
int a[20];
int ans=0;
void find(int l,int r){
	bool f1,f2;
	for(int i=l+1;i<=r;++i){
		if(a[i]<a[i-1]){
			f1=1;break;
		}
	}
	if(!f1){
		ans=max(ans,r-l+1);
		return;
	}
	int mid=l+r>>1;
	find(l,mid);find(mid+1,r);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
	}
	if(n==1){
		puts("1");
		return 0;
	}
	find(1,n);
	printf("%d",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int n;
int a[20];
int ans=0;
void find(int l,int r){
	bool f1,f2;
	for(int i=l+1;i<=r;++i){
		if(a[i]<a[i-1]){
			f1=1;break;
		}
	}
	if(!f1){
		ans=max(ans,r-l+1);
		return;
	}
	int mid=l+r>>1;
	find(l,mid);find(mid+1,r);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
	}
	if(n==1){
		puts("1");
		return 0;
	}
	find(1,n);
	printf("%d",ans);
}


#include<cstdio>
#include<algorithm>
using namespace std;
int n;
int a[20];
int ans=1;
void find(int l,int r){
	bool f1=0,f2=0;
	if(l>=r)return;
	for(int i=l+1;i<=r;++i){
		if(a[i]<a[i-1]){
			f1=1;break;
		}
	}
	if(!f1){
		ans=max(ans,r-l+1);
		return;
	}
	int mid=l+r>>1;
	find(l,mid);find(mid+1,r);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
	}
	if(n==1){
		puts("1");
		return 0;
	}
	find(1,n);
	printf("%d",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int n;
int a[20];
int ans=0;
void find(int l,int r){
	bool f1=0;
	if(l>=r)return;
	for(int i=l+1;i<=r;++i){
		if(a[i]<a[i-1]){
			f1=1;break;
		}
	}
	if(!f1){
		ans=max(ans,r-l+1);
		return;
	}
	int mid=l+r>>1;
	find(l,mid);find(mid+1,r);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
	}
	if(n==1){
		puts("1");
		return 0;
	}
	find(1,n);
	printf("%d",ans);
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    cin >> n;

    int arr[n];

    for(int i=0;i<n;i++)
        cin >> arr[i];

    int split_point = 1;
    int hi_pos, lo_pos;

    while(split_point != n)
    {
        int range = n/split_point;
        hi_pos = 0;
        lo_pos = hi_pos + range;

        for(int i=0;i<split_point;i++)
        {
            if(is_sorted(arr+hi_pos, arr+lo_pos))
            {
                cout<<range<<endl;
                return 0;
            }

            hi_pos = lo_pos;
            lo_pos += range;
        }

        split_point *= 2;
    }

    cout<<"1\n";

    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;

    int arr[n];

    for(int i=0;i<n;i++)
        cin >> arr[i];

    bool flag = false;

    for(int i=0;i<n-2;i++)
    {
        if(arr[i] > arr[i+1])
        {
            flag = true;
            break;
        }
    }

    if(!flag)
    {
        cout<<n<<endl;
        return 0;
    }

    int iterateNum = 2;
    int iterateInterval = n/iterateNum;

    int startPoint = 0;
    int endPoint = startPoint + iterateInterval - 1;

    flag = false;

    while(iterateNum != n)
    {
        for(int i=0;i<iterateNum;i++)
        {
            for(int j=startPoint;j<=endPoint-1;j++)
            {
                if(arr[j] > arr[j+1])
                {
                    flag = true;
                    break;
                }
            }

            if(!flag)
            {
                cout<<iterateInterval<<endl;
                return 0;
            }

            flag = false;

            startPoint = endPoint + 1;
            endPoint += iterateInterval;
        }

        iterateNum *= 2;
        iterateInterval = n/iterateNum;

        startPoint = 0;
        endPoint = startPoint + iterateInterval - 1;
    }

    if(!flag)
        cout<<"1\n";

    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;

    int arr[n];

    for(int i=0;i<n;i++)
        cin >> arr[i];

    bool flag = false;

    if(n == 1)
    {
        cout<<"1\n";
        return 0;
    }

    if(n == 2)
    {
        if(arr[0] < arr[1])
            cout<<"2\n";
        else
            cout<<"1\n";

        return 0;
    }

    for(int i=0;i<n-2;i++)
    {
        if(arr[i] > arr[i+1])
        {
            flag = true;
            break;
        }
    }

    if(!flag)
    {
        cout<<n<<endl;
        return 0;
    }

    int iterateNum = 2;
    int iterateInterval = n/iterateNum;

    int startPoint = 0;
    int endPoint = startPoint + iterateInterval - 1;

    flag = false;

    while(iterateNum != n)
    {
        for(int i=0;i<iterateNum;i++)
        {
            for(int j=startPoint;j<=endPoint-1;j++)
            {
                if(arr[j] > arr[j+1])
                {
                    flag = true;
                    break;
                }
            }

            if(!flag)
            {
                cout<<iterateInterval<<endl;
                return 0;
            }

            flag = false;

            startPoint = endPoint + 1;
            endPoint += iterateInterval;
        }

        iterateNum *= 2;
        iterateInterval = n/iterateNum;

        startPoint = 0;
        endPoint = startPoint + iterateInterval - 1;
    }

    if(!flag)
        cout<<"1\n";

    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;

    int arr[n];

    for(int i=0;i<n;i++)
        cin >> arr[i];

    bool flag = false;

    if(n == 1)
    {
        cout<<"1\n";
        return 0;
    }

    if(n == 2)
    {
        if(arr[0] < arr[1])
            cout<<"2\n";
        else
            cout<<"1\n";

        return 0;
    }

    for(int i=0;i<n-1;i++)
    {
        if(arr[i] > arr[i+1])
        {
            flag = true;
            break;
        }
    }

    if(!flag)
    {
        cout<<n<<endl;
        return 0;
    }

    int iterateNum = 2;
    int iterateInterval = n/iterateNum;

    int startPoint = 0;
    int endPoint = startPoint + iterateInterval - 1;

    flag = false;

    while(iterateNum != n)
    {
        for(int i=0;i<iterateNum;i++)
        {
            for(int j=startPoint;j<=endPoint-1;j++)
            {
                if(arr[j] > arr[j+1])
                {
                    flag = true;
                    break;
                }
            }

            if(!flag)
            {
                cout<<iterateInterval<<endl;
                return 0;
            }

            flag = false;

            startPoint = endPoint + 1;
            endPoint += iterateInterval;
        }

        iterateNum *= 2;
        iterateInterval = n/iterateNum;

        startPoint = 0;
        endPoint = startPoint + iterateInterval - 1;
    }

    if(!flag)
        cout<<"1\n";

    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;

    int arr[n];

    for(int i=0;i<n;i++)
        cin >> arr[i];

    bool flag = false;

    if(n == 1)
    {
        cout<<"1\n";
        return 0;
    }

    for(int i=0;i<n-1;i++)
    {
        if(arr[i] > arr[i+1])
        {
            flag = true;
            break;
        }
    }

    if(!flag)
    {
        cout<<n<<endl;
        return 0;
    }

    int iterateNum = 2;
    int iterateInterval = n/iterateNum;

    int startPoint = 0;
    int endPoint = startPoint + iterateInterval - 1;

    flag = false;

    while(iterateNum != n)
    {
        for(int i=0;i<iterateNum;i++)
        {
            for(int j=startPoint;j<=endPoint-1;j++)
            {
                if(arr[j] > arr[j+1])
                {
                    flag = true;
                    break;
                }
            }

            if(!flag)
            {
                cout<<iterateInterval<<endl;
                return 0;
            }

            flag = false;

            startPoint = endPoint + 1;
            endPoint += iterateInterval;
        }

        iterateNum *= 2;
        iterateInterval = n/iterateNum;

        startPoint = 0;
        endPoint = startPoint + iterateInterval - 1;
    }

    if(!flag)
        cout<<"1\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, a[17];

bool sorted(int l, int r) {
	for (int i = l; i < r; i++) {
		if (a[i + 1] < a[i]) {
			return false;
		}
	}
	return true;
}

int solve(int l, int r) {
	if (sorted(l, r)) {
		return r - l + 1;
	}
	else {
		int mid = (l + r) / 2;
		return max(solve(l, mid), solve(mid + 1, r));
	}
}

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	cout << solve(1, n);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, ans, a[20];

void go(int l, int r) {
	bool can = true;
	for (int i = l; i < r; i++) {
		if (a[i] < a[i - 1]) {
			can = false;
		}
	}
	if (can) {
		ans = max(ans, r - l + 1);
	}
	else {
		if (l != (l + r) / 2 + 1) {
			go((l + r) / 2 + 1, r);
		}
		if ((l + r) / 2 + 1 != r) {
			go(l, (l + r) / 2 + 1);
		}
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	go(1, n);
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, ans, a[20];

void go(int l, int r) {
	bool can = true;
	for (int i = l; i < r; i++) {
		if (a[i] < a[i - 1]) {
			can = false;
		}
	}
	if (can) {
		ans = max(ans, r - l + 1);
	}
	else {
		if (l * 2 <= r) {
			go(l * 2, r);
		}
		if (l <= r / 2) {
			go(l, r / 2);
		}
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	go(1, n);
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, a[17];

bool sorted(int l, int r) {
	for (int i = l; i < r; i++) {
		if (a[i + 1] < a[i]) {
			return false;
		}
	}
	return true;
}

int solve(int l, int r) {
	if (sorted(l, r)) {
		return r - l + 1;
	}
	else {
		int mid = (l + r / 2);
		return max(solve(l, mid), solve(mid + 1, r));
	}
}

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	cout << solve(1, n);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, ans, a[20];

bool pow2(int x) {
	return ((x & (x - 1)) == 0);
}

bool sorted(int l, int r){
	for (int i = l; i < r; i++) {
		if (a[i + 1] < a[i]) {
			return false;
		}
	}
	return true;
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ans = 1;
	for (int len = 2; len <= n; len *= 2) {
		for (int i = 0; i < n; i++) {
			int j = i + len - 1;
			if (pow2(i + 1) && pow2(j + 1) && sorted(i, j)) {
				ans = max(ans, len);
			}
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, ans, a[20];

bool pow2(int x) {
	return ((x & (x - 1)) == 0);
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = i; j < n; j++) {
			int len = j - i + 1;
			bool can = true;
			if (pow2(len) && pow2(i + 1) && pow2(j + 1)) {
				//cout << len << endl;
				for (int k = i; k < j; k++) {
					if (a[k + 1] < a[k]) {
						can = false;
					}
				}
				if (can) {
					ans = max(ans, len);
				}
			}
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mii make_pair<int ,int>
#define mll make_pair<ll, ll>
#define rep(a, b) for (int i = a; i < b; ++i)
#define vi vector <int>
#define vvi vector <vector <int> >
#define vl vector <ll>
#define vvl vector <vector <ll> >
#define vb vector <bool>
#define vvb vector <vector <bool> >

vi v(16);

int check(int a, int b)
{
    if (is_sorted(v.begin() + a, v.begin() + b))
        return b - a;
    else
        return max(check(a, (a + b) / 2), check(b, a + b));
}

int main()
{
    ios::sync_with_stdio(false);
	cin.tie(0);
    int n;
    cin >> n;
    rep(0, n)
        cin >> v[i];
    cout << check(0, n) << endl;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mii make_pair<int ,int>
#define mll make_pair<ll, ll>
#define rep(a, b) for (int i = a; i < b; ++i)
#define vi vector <int>
#define vvi vector <vector <int> >
#define vl vector <ll>
#define vvl vector <vector <ll> >
#define vb vector <bool>
#define vvb vector <vector <bool> >

vi v(16);

int check(int a, int b)
{
    if (is_sorted(v.begin() + a, v.begin() + b))
        return b - a;
    else
        return max(check(a, (a + b) / 2), check((a + b) / 2, a + b));
}

int main()
{
    ios::sync_with_stdio(false);
	cin.tie(0);
    int n;
    cin >> n;
    rep(0, n)
        cin >> v[i];
    cout << check(0, n) << endl;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mii make_pair<int ,int>
#define mll make_pair<ll, ll>
#define rep(a, b) for (int i = a; i < b; ++i)
#define vi vector <int>
#define vvi vector <vector <int> >
#define vl vector <ll>
#define vvl vector <vector <ll> >
#define vb vector <bool>
#define vvb vector <vector <bool> >

vi v(200);

int check(int a, int b)
{
    if (is_sorted(v.begin() + a, v.begin() + b))
        return b - a;
    else
        return max(check(a, (a + b) / 2), check((a + b) / 2, b));
}

int main()
{
    ios::sync_with_stdio(false);
	cin.tie(0);
    int n;
    cin >> n;
    rep(0, n)
        cin >> v[i];
    cout << check(0, n) << endl;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mii make_pair<int ,int>
#define mll make_pair<ll, ll>
#define rep(a, b) for (int i = a; i < b; ++i)
#define vi vector <int>
#define vvi vector <vector <int> >
#define vl vector <ll>
#define vvl vector <vector <ll> >
#define vb vector <bool>
#define vvb vector <vector <bool> >

vi v(200);

int check(int a, int b)
{
    if (is_sorted(v.begin() + a, v.begin() + b))
        return b - a;
    else
        return max(check(a, (a + b) / 2), check((a + b) / 2, a + b));
}

int main()
{
    ios::sync_with_stdio(false);
	cin.tie(0);
    int n;
    cin >> n;
    rep(0, n)
        cin >> v[i];
    cout << check(0, n) << endl;
}


#include<bits/stdc++.h>
using namespace std;

vector<int> v(16);
int n;

int val(int i, int j){
    int k;
    if(j-i==1){
        if(v[i]<v[j])   return 2;
        else    return 1;
    }
    for(k=i;k<=j-1;k++){
        if(v[k]>v[k+1])    break;
    }
    if(k==j){
        return j-i+1;
    }
    k = (j-i+1)/2;
    return max(val(i,i+k-1) , val(i+k,j));
}

int main(){
    int m,i,j;
    cin>>n;
    if(n==1){
        cout<<"1";
        exit(0);
    }
    v.resize(n);
    for(i=0;i<n;i++)    cin>>v[i];
    cout<<val(0, n-1);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

vector<int> v(16);
int n;

int val(int i, int j){
    int k;
    if(j-i==1){
        if(v[i]<v[j])   return 2;
        else    return 1;
    }
    for(k=i;k<j-1;k++){
        if(v[k]>v[k+1])    break;
    }
    if(k==j-1){
        return j-i+1;
    }
    k = (j-i+1)/2;
    return max(val(i,i+k-1) , val(i+k,j));
}

int main(){
    int m,i,j;
    cin>>n;
    v.resize(n);
    for(i=0;i<n;i++)    cin>>v[i];
    cout<<val(0, n-1);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

vector<int> v(16);
int n;

int val(int i, int j){
    int k;
    if(j-i==1){
        if(v[i]<v[j])   return 2;
        else    return 1;
    }
    for(k=i;k<j-1;k++){
        if(v[k]>v[k+1])    break;
    }
    if(k==j-1){
        return j-i+1;
    }
    k = (j-i+1)/2;
    return max(val(i,i+k-1) , val(i+k,j));
}

int main(){
    int m,i,j;
    cin>>n;
    if(n==1){
        cout<<"1";
        exit(0);
    }
    v.resize(n);
    for(i=0;i<n;i++)    cin>>v[i];
    cout<<val(0, n-1);
    return 0;
}


#include<iostream>
using namespace std;
int m(int a,int b){
    if(a>b)
        return a;
    return b;
}
int max(int x,int y,int a[17]){
    bool b=true;
    for(int i=x+1;i<=y;i++){
        if(a[i]<a[i-1]){
            b=false;
            break;
        }
    }int xy=(x+y)/2;
    if(b)
        return y-x+1;
    else return m(max(x,xy),max(xy+1,y));
}
int main(){
    int n,x=1;
    cin>>n;
    int a[17];
    for(int i=1;i<n;i++){
        cin>>a[i];
    }n++;
    cout<<max(x,n,a);
}


#include<iostream>
using namespace std;
int m(int a,int b){
    if(a>b)
        return a;
    return b;
}
int max(int x,int y,int a[17]){
    bool b=true;
    for(int i=x+1;i<=y;i++){
        if(a[i]<a[i-1]){
            b=false;
            break;
        }
    }int xy=(x+y)/2;
    if(b){
        return y-x+1;
    }
    else {
        int m1=max(x,xy,a),m2=max(xy+1,y,a);
        return m(m1,m2);
    }
}
int main(){
    int n,x=1;
    cin>>n;
    int a[17];
    for(int i=1;i<n+1;i++){
        cin>>a[i];
    }
    cout<<max(x,n,a);
}


#include<iostream>
using namespace std;
int m(int a,int b){
    if(a>b)
        return a;
    return b;
}
int max(int x,int y,int a[17]){
    bool b=true;
    for(int i=x+1;i<=y;i++){
        if(a[i]<a[i-1]){
            b=false;
            break;
        }
    }int xy=(x+y)/2;
    if(b)
        return y-x;
    else return m(max(x,xy),max(xy+1,y));
}
int main(){
    int n,x=1;
    cin>>n;
    int a[17];
    for(int i=1;i<n;i++){
        cin>>a[i];
    }n++;
    cout<<max(x,n,a);
}


#include<iostream>
using namespace std;
int m(int a,int b){
    if(a>b)
        return a;
    return b;
}
int max(int x,int y,int a[17]){
    bool b=true;
    for(int i=x+1;i<=y;i++){
        if(a[i]<a[i-1]){
            b=false;
            break;
        }
    }int xy=(x+y)/2;
    if(b)
        return 4;
    else return m(max(x,xy),max(xy+1,y));
}
int main(){
    int n,x=1;
    cin>>n;
    int a[17];
    for(int i=1;i<n;i++){
        cin>>a[i];
    }n++;
    cout<<max(x,n,a);
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define recout(x) return cout << (x) , 0 ;
using namespace std ;

//map <long double , long long int > mp;
string s , t ;
//set <long double> s[N];
//char c[N];
//bool mark[N], vis[N];
//vector <long long int> v[N];
//queue <long log int> q[N];
long double PI = 3.1415926535897932;
const int N = 1e5 + 10 ;
long long int ans , sum , cnt ;
long long int a[N] , b[N] , c[N] ;
long long int n , p , m , k , mx = 1;

int main (){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cout << setprecision(12) << fixed ;
	cin >> n ;
	for(int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	for(int i = 0 ; i < 5 ; i++){
		for(int j = 0 ; j < n / pow(2 , i) ; j++){
			long long int h = 1 ;
			for(int p = j * pow(2 , i) ; p <(j + 1) * (pow(2 , i)) - 1 ; p++){
				if(a[p + 1] >= a[p]){
					h++ ;
				}else{
					h = 1;
					break ;
				}
				mx = max(mx , h) ;
			}
		}
	}
	cout << mx ;
	return 0 ;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define recout(x) return cout << (x) , 0 ;
using namespace std ;

//map <long double , long long int > mp;
string s , t ;
//set <long double> s[N];
//char c[N];
//bool mark[N], vis[N];
//vector <long long int> v[N];
//queue <long log int> q[N];
long double PI = 3.1415926535897932;
const int N = 1e5 + 10 ;
long long int ans , sum , cnt ;
long long int a[N] , b[N] , c[N] ;
long long int n , p , m , k , mx = 1;

int main (){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cout << setprecision(12) << fixed ;
	cin >> n ;
	if(n == 1 ){
		cout << 1 ;
		return 0 ;
	}
	for(int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	for(int i = 0 ; i < 5 ; i++){
		for(int j = 0 ; j < n / pow(2 , i) ; j++){
			long long int h = 1 ;
			for(int p = j * pow(2 , i) ; p <(j + 1) * (pow(2 , i)) - 1 ; p++){
				if(a[p + 1] >= a[p]){
					h++ ;
				}else{
					h = 1;
					break ;
				}
				mx = max(mx , h) ;
			}
		}
	}
	cout << mx ;
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std;

int a[20];

int recurse(int l, int r)
{

    int mid;
    for(int i=l; i<=r; i++)
    {
        if(a[i]>a[i+1])
        {
        mid = (r+l)/2;
        return max(recurse(r,mid),recurse(mid+1,l));
        }
    }
    return(r-l+1);
}

int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    int res=recurse(0,n-1);
    cout<<res;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int a[20];

int recurse(int l, int r)
{

    int mid;
    for(int i=l; i<=r; i++)
    {
        if(a[i]>a[i+1])
        {
        mid = (r+l)/2;
        return max(recurse(l,mid),recurse(mid+1,r));
        }
    }
    return(r-l+1);
}

int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    int res=recurse(0,n-1);
    cout<<res;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,c=1,prev;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
     prev=a[0];
    for(int i=1; i<n; i++)
    {
        if(a[i]>=prev)
        {
            c++;
            prev=a[i];
        }
    }
    cout<<c;
}


#include<bits/stdc++.h>
using namespace std;

int a[20];

int recurse(int r, int l)
{

    int mid;
    for(int i=l; i<=r; i++)
    {
        if(a[i]>a[i+1])
        {
        mid = (r+l)/2;
        return max(recurse(r,mid),recurse(mid+1,l));
        }
    }
    return(r-l+1);
}

int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    int res=recurse(0,n-1);
    cout<<res;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int a[20];

int recurse(int l, int r)
{

    int mid;
    for(int i=l; i<r; i++)
    {
        if(a[i]>a[i+1])
        {
        mid = (r+l)/2;
        return max(recurse(l,mid),recurse(mid+1,r));
        }
    }
    return(r-l+1);
}

int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    int res=recurse(0,n-1);
    cout<<res;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,c=1,prev;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
     prev=a[0];
    for(int i=1; i<n; i++)
    {
        if(a[i]>=prev)
        {
            c++;
            prev=a[i];
        }
        else
            break;
    }
    cout<<c;
}


#include<bits/stdc++.h>
using namespace std;

int a[20];

int recurse(int r, int l)
{

    int middle;
    for(int i=0; i<n; i++)
    {
        if(a[i]>a[i+1])
        {
        mid = (r+l)/2;
        return max(recurse(r,middle),recurse(middle+1,l));
        }
    }
    return(r-l+1);
}

int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    int res=recurse(0,n-1);
    cout<<res;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> v(n);
    for (int i=0;i<n;i++)
        cin>>v[i];
    int k=0;
    int j;
    for (int i=0;i<n/2;i++)
    {
        for (j=k;j<n-1;j++)
            if (v[j]>v[j+1])
                break;
        if (j==n-1)
            break;
        if (j>=(n-k)/2+k-1)
        {
            n=(n-k)/2+k;
            break;
        }
        else
            k=(n-k)/2+k;
    }
    cout<<n-k;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> v(n);
    for (int i=0;i<n;i++)
        cin>>v[i];
    for (int len=n;len>0;len/=2){
        for (int s=0;s<n;s+=len){
            bool f=true;
            for (int j=1;j<len;j++)
                if (v[s+j]<v[s+j-1]){
                    f=false;
                    break;
                }
            if (f){
                cout<<len;
                return 0;
            }
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> v(n);
    for (int i=0;i<n;i++)
        cin>>v[i];
    int k=0;
    int j;
    for (int i=0;i<n/2;i++)
    {
        for (j=k;j<n-1;j++)
            if (v[j]>v[j+1])
                break;
        if (j==n-1)
            break;
        if (j>=(n-k)/2-1)
        {
            n=(n-k)/2+k;
            break;
        }
        else
            k=(n-k)/2+k;
    }
    cout<<n-k;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> v(n);
    for (int i=0;i<n;i++)
        cin>>v[i];
    int k=0;
    int j=0;
    for (int i=0;i<n/2;i++)
    {
        for (j=k;j<n-1;j++)
        {
            if (v[j]>v[j+1])
            {
                k = (n-k)/2+k;
                break;
            }
        }
        if (j==n-2)
            break;
    }
   cout<<n-k;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
#define ll long long
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int a[20];
    int mmin[20];
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    int k1=1;
    for(int i=1;i<n;i++)
    {
        if(a[i-1]<=a[i])
            k1++;
        else
            break;
    }
    int k2=1;
    for(int i=n-1;i>0;i--)
    {
        if(a[i-1]<=a[i])
            k2++;
        else
            break;
    }
    //printf("%d %d",k1,k1);
    printf("%d\n",max(k1,k2));
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
#define ll long long
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int a[20];
    int mmin[20];
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    mmin[0]=1;
    int k=0;
    for(int i=1; i<n; i++)
    {
        if(a[i]>=a[i-1])
            mmin[k]++;
        else
        {
           k++;
           mmin[k]=1;
        }
    }
    int minn=120;
    for(int i=0;i<=k;i++)
    {
        if(mmin[i]<minn)
            minn=mmin[i];
    }
    printf("%d\n",minn);
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
#define ll long long
using namespace std;
int a[20];
int fun(int i,int j)
{
    if(is_sorted(a+i,a+j))
        return j-i;
    return max(fun(i,(i+j)/2),fun((i+j)/2,j));
}
int main()
{
    int n;
    scanf("%d",&n);

    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    printf("%d\n",fun(0,n));
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
#define ll long long
using namespace std;
int a[20];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=n;i>=1;i>>=1)//每次数组的长度都缩小一半,n是2的n次方
    {
        for(int j=0;j<n;j+=i)//枚举每一段
        {
            bool ans=1;
            for(int k=j+1;k<j+i;k++)
            {
                ans&=(a[k]>a[k-1]);
            }
            if(ans){printf("%d\n",i);return 0;}//如果符合就输出
        }
    }
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
#define ll long long
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=n;i>=1;i>>=1)//每次数组的长度都缩小一半,n是2的n次方
    {
        for(int j=0;j<n;j+=i)//枚举每一段
        {
            bool ans=1;
            for(int k=j+1;k<j+i;k++)
            {
                ans&=(a[k]>a[k-1]);
            }
            if(ans){printf("%d\n",i);return 0;}//如果符合就输出
        }
    }
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
#define ll long long
using namespace std;
int a[20];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=n;i>=1;i>>=1)//每次数组的长度都缩小一半,n是2的n次方
    {
        for(int j=0;j<n;j+=i)//枚举每一段
        {
            bool ans=1;
            for(int k=j+1;k<j+i;k++)
            {
                ans&=(a[k]>=a[k-1]);
            }
            if(ans){printf("%d\n",i);return 0;}//如果符合就输出
        }
    }
}


#include <iostream>
using namespace std;
int n,v[1029],nr=1;
inline bool sortat(int i,int j)
{
    for(int k=i+1;k<=j;k++)
        if(v[k]<v[k-1])
            return 0;
    return 1;
}
int f(int i,int j)
{
    if(j-i)
    {
        if(sortat(i,j))
            {nr=max(j-i+1,nr);return 0;}
        else
        {
            f(i,j/2);
            f((i+j-1)/2+1,j);
        }
    }
    return 0;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>v[i];
    f(1,n);
    cout<<nr<<'\n';
    return 0;
}


#include <iostream>
using namespace std;
int n,v[1029],nr=1;
inline bool sortat(int i,int j)
{
    for(int k=i+1;k<=j;k++)
        if(v[k]<v[k-1])
            return 0;
    return 1;
}
int fn(int i,int j)
{
    if(j-i)
    {
        if(sortat(i,j))
            {nr=max(j-i+1,nr);return 0;}
        else
        {
            fn(i,(i+j-1)/2);
            fn((i+j-1)/2+1,j);
        }
    }
    return 0;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>v[i];
    fn(1,n);
    cout<<nr<<'\n';
    return 0;
}


#include <fstream>
using namespace std;
ifstream f("thanos.in");
ofstream g("thanos.out");
int n,v[1029],nr=1;
inline bool sortat(int i,int j)
{
    for(int k=i+1;k<=j;k++)
        if(v[k]<v[k-1])
            return 0;
    return 1;
}
int fn(int i,int j)
{
    if(j-i)
    {
        if(sortat(i,j))
            {nr=max(j-i+1,nr);return 0;}
        else
        {
            fn(i,(i+j-1)/2);
            fn((i+j-1)/2+1,j);
        }
    }
    return 0;
}
int main()
{
    f>>n;
    for(int i=1;i<=n;i++)
        f>>v[i];
    fn(1,n);
    g<<nr<<'\n';
    return 0;
}


#include <iostream>
using namespace std;
int n,v[17],nr=1;
inline bool sortat(int i,int j)
{
    for(int k=i+1;k<=j;k++)
        if(v[k]<v[k-1])
            return 0;
    return 1;
}
int f(int i,int j)
{
    if(j-i)
    {
        if(sortat(i,j))
            {nr=max(j-i+1,nr);return 0;}
        else
        {
            f(i,j/2);
            f((i+j-1)/2+1,j);
        }
    }
    return 0;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>v[i];
    f(1,n);
    cout<<nr<<'\n';
    return 0;
}


#include <iostream>
using namespace std;
int n,v[20],nr=1;
inline bool sortat(int i,int j)
{
    for(int k=i+1;k<=j;k++)
        if(v[k]<=v[k-1])
            return 0;
    return 1;
}
int f(int i,int j)
{
    if(j-i)
    {
        if(sortat(i,j))
            {nr=max(j-i+1,nr);return 0;}
        else
        {
            f(i,j/2);
            f((i+j-1)/2+1,j);
        }
    }
    return 0;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>v[i];
    f(1,n);
    cout<<nr<<'\n';
    return 0;
}


#include <iostream>
#include <vector>

template<typename T>
void GetVectorFromInput(std::vector<T>& val) {
	for (int i = 0; i < val.size(); ++i) {
		std::cin >> val[i];
	}
	return;
}

int main() {
	int size;
	std::cin >> size;
	std::vector<int> numbers(size);
	if (size == 1) return 1;
	GetVectorFromInput<int>(numbers);
	std::vector<int> sorted(size, 1);
	int cur_max_sorted = 1;
	for (int n = 1; (1 << n) <= size; ++n) {
		for (int i = 0; i < (size>>n); ++i) {
			int left = (1 << n)*i + (1 << (n - 1)) - 1;
			int right = (1 << n)*i + (1 << n) - 1;
			if (sorted[left] && sorted[right]
				&& numbers[left] < numbers[left+1]) {
				if (cur_max_sorted < (1 << n)) cur_max_sorted = (1 << n);
			}
			else {
				sorted[right] = 0;
			}
		}
	}
	std::cout << cur_max_sorted << std::endl;
}


#include <iostream>
#include <vector>

void GetVectorFromInput(std::vector<T>& val) {
	for (int i = 0; i < val.size(); ++i) {
		std::cin >> val[i];
	}
	return;
}

int main() {
	int size;
	std::cin >> size;
	std::vector<int> numbers(size);
	if (size == 1) return 1;
	GetVectorFromInput<int>(numbers);
	std::vector<int> sorted(size, 1);
	int cur_max_sorted = 1;
	for (int n = 1; (1 << n) <= size; ++n) {
		for (int i = 0; i < (size>>n); ++i) {
			int left = (1 << n)*i + (1 << (n - 1)) - 1;
			int right = (1 << n)*i + (1 << n) - 1;
			if (sorted[left] && sorted[right]
				&& numbers[left] < numbers[left+1]) {
				if (cur_max_sorted < (1 << n)) cur_max_sorted = (1 << n);
			}
			else {
				sorted[right] = 0;
			}
		}
	}
	std::cout << cur_max_sorted << std::endl;
}


#include <iostream>
#include <vector>

template<typename T>
void GetVectorFromInput(std::vector<T>& val) {
	for (int i = 0; i < val.size(); ++i) {
		std::cin >> val[i];
	}
	return;
}

int main() {
	int size;
	std::cin >> size;
	std::vector<int> numbers(size);
	if (size == 1) return 1;
	GetVectorFromInput<int>(numbers);
	std::vector<int> sorted(size, 1);
	int cur_max_sorted = 1;
	for (int n = 1; (1 << n) <= size; ++n) {
		for (int i = 0; i < (size>>n); ++i) {
			int left = (1 << n)*i + (1 << (n - 1)) - 1;
			int right = (1 << n)*i + (1 << n) - 1;
			if (sorted[left] && sorted[right]
				&& numbers[left] <= numbers[left+1]) {
				if (cur_max_sorted < (1 << n)) cur_max_sorted = (1 << n);
			}
			else {
				sorted[right] = 0;
			}
		}
	}
	std::cout << cur_max_sorted << std::endl;
}


#include <iostream>
#include <vector>

template<typename T>
void GetVectorFromInput(std::vector<T>& val) {
	for (int i = 0; i < val.size(); ++i) {
		std::cin >> val[i];
	}
	return;
}

int main() {
	int size;
	std::cin >> size;
	std::vector<int> numbers(size);
	GetVectorFromInput<int>(numbers);
    if (size == 1) return 1;
	std::vector<int> sorted(size, 1);
	int cur_max_sorted = 1;
	for (int n = 1; (1 << n) <= size; ++n) {
		for (int i = 0; i < (size>>n); ++i) {
			int left = (1 << n)*i + (1 << (n - 1)) - 1;
			int right = (1 << n)*i + (1 << n) - 1;
			if (sorted[left] && sorted[right]
				&& numbers[left] <= numbers[left+1]) {
				if (cur_max_sorted < (1 << n)) cur_max_sorted = (1 << n);
			}
			else {
				sorted[right] = 0;
			}
		}
	}
	std::cout << cur_max_sorted << std::endl;
}


#include <iostream>
#include <vector>

template<typename T>
void GetVectorFromInput(std::vector<T>& val) {
	for (int i = 0; i < val.size(); ++i) {
		std::cin >> val[i];
	}
	return;
}

int main() {
	int size;
	std::cin >> size;
	std::vector<int> numbers(size);
	GetVectorFromInput<int>(numbers);
	std::vector<int> sorted(size, 1);
	int cur_max_sorted = 1;
	for (int n = 1; (1 << n) <= size; ++n) {
		for (int i = 0; i < (size>>n); ++i) {
			int left = (1 << n)*i + (1 << (n - 1)) - 1;
			int right = (1 << n)*i + (1 << n) - 1;
			if (sorted[left] && sorted[right]
				&& numbers[left] <= numbers[left+1]) {
				if (cur_max_sorted < (1 << n)) cur_max_sorted = (1 << n);
			}
			else {
				sorted[right] = 0;
			}
		}
	}
	std::cout << cur_max_sorted << std::endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define x first
#define y second
int n,i,cnt,maxans,a[20];
void func(int start,int end){
    int f=0;
    for(int i=start+1;i<=end;i++){
        if(a[i]<a[i-1]){
            f=1;
        }
    }
    if(f==0){
        maxans=end-start+1;
        return;
    }
    else{
        func(start,(start+end)/2);
        func((start+end)/2+1,end);
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //assert(freopen("input.txt","r",stdin));
    //assert(freopen("output.txt","w",stdout));
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>a[i];
    }
    func(1,n);
    cout<<maxans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define x first
#define y second
int n,i,cnt,maxans,a[20];
void func(int start,int end){
    int f=0;
    for(int i=start+1;i<=end;i++){
        if(a[i]<a[i-1]){
            f=1;
        }
    }
    if(f==0){
        maxans=max(maxans,end-start+1);
        return;
    }
    else{
        func(start,(start+end)/2);
        func((start+end)/2+1,end);
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //assert(freopen("input.txt","r",stdin));
    //assert(freopen("output.txt","w",stdout));
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>a[i];
    }
    func(1,n);
    cout<<maxans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define x first
#define y second
int n,i,cnt,maxans,a[20],j,k;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //assert(freopen("input.txt","r",stdin));
    //assert(freopen("output.txt","w",stdout));
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>a[i];
    }
    for(i=1;i<=n;i++){
        for(j=i;j<=n;j++){
            int f=0;
            for(k=i+1;k<=j;k++){
                if(a[k]<a[k-1]){
                    f=1;
                }
            }
            if(f==0){
                maxans=max(maxans,j-i+1);
            }
        }
    }
    cout<<maxans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define x first
#define y second
int n,i,cnt;
set<int>s;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //assert(freopen("input.txt","r",stdin));
    //assert(freopen("output.txt","w",stdout));
    int val=1;
    while(val<100){
        s.insert(val);
        val*=2;
    }
    cin>>n;
    for(i=1;i<=n;i++){
        int x;
        cin>>x;
        if(s.find(x)!=s.end()){
            cnt++;
        }
    }
    cout<<cnt;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define x first
#define y second
int n,i,cnt,maxans,a[20];
void func(int start,int end){
    int f=0;
    for(int i=start+1;i<=end;i++){
        if(a[i]<a[i-1]){
            f=1;
        }
    }
    if(f==0){
        maxans=end-start+1;
    }
    else{
        func(start,(start+end)/2);
        func((start+end)/2+1,end);
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //assert(freopen("input.txt","r",stdin));
    //assert(freopen("output.txt","w",stdout));
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>a[i];
    }
    func(1,n);
    cout<<maxans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

bool issort(vector<int> &a,int l,int k)
{
bool flag=true;
for(int i=l;i<k-1;i++)
{
if(a[i]>a[i+1])
{
flag=false;
break;
}
}
return flag;
}

int main()
{
int n;
cin>>n;
vector<int> a;
int l;
for(int i=0;i<n;i++)
{
cin>>l;
a.push_back(l);
}
int ans=n;
for(int i=0;i<n;i+=ans)
{
if(issort(a,i,i+ans-1))
{
cout<<ans<<endl;
break;
}
ans=ans/2;
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;

bool issort(vector<int> &a,int l,int k)
{
bool flag=true;
for(int i=l;i<k-1;i++)
{
if(a[i]>a[i+1])
{
flag=false;
break;
}
}
return flag;
}

int main()
{
int n;
cin>>n;
vector<int> a;
int l;
for(int i=0;i<n;i++)
{
cin>>l;
a.push_back(l);
}
int ans=n;
for(int i=0;i<n;i+=ans)
{
if(issort(a,i,i+ans-1))
{
cout<<ans<<endl;
break;
}
ans=ans*2;
}
return 0;
}


#include<bits/stcd++.h>
using namespace std;

bool issort(vector<int> &a,int l,int k)
{
bool flag=true;
for(int i=l;i<k-1;i++)
{
if(a[i]>a[i+1])
{
flag=false;
break;
}
}
return flag;
}

int main()
{
int n;
cin>>n;
vector<int> a;
int l;
for(int i=0;i<n;i++)
{
cin>>l;
a.push_back(l);
}
int ans=n;
for(int i=0;i<n;i+=ans)
{
if(issort(a,i,i+ans-1))
{
cout<<ans<<endl;
break;
}
ans=ans*2;
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;

bool issort(vector<int> &a,int l,int k)
{
//cout<<"HI "<<l<<" "<<k<<endl;
bool flag=true;
for(int i=l;i<k-1;i++)
{
if(a[i]>a[i+1])
{
flag=false;
break;
}
}
return flag;
}

int main()
{
int n;
cin>>n;
vector<int> a;
int l;
for(int i=0;i<n;i++)
{
cin>>l;
a.push_back(l);
}
int o=1;
int ans=n;
while(o)
{
for(int i=0;i<n;i+=ans)
{
//cout<<"ans:"<<ans<<" ";
if(issort(a,i,i+ans))
{
cout<<ans<<endl;
o=0;
break;
}
}
ans=ans/2;
}
return 0;
}


#include <iostream>

using namespace std;
int n;
int a[100];
int res;

void dfs(int left, int right) {
	if(right - left <= 0) {
		res = min(res, 1);
		return ;
	}
	res = min(res, right - left + 1);
	int mid = (left + right) / 2;
	for(int i = left; i < right; i++) {
		if(a[i] > a[i+1]) {
			dfs(left, mid);
			dfs(mid+1, right);
			break;
		}
	}
}

int main(int argc, char *argv[]) {
	cin >> n;
	res = 100000;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	dfs(0, n-1);
	cout << res << endl;
	return 0;
}


#include <iostream>

using namespace std;
int n;
int a[10000];
int res;

void dfs(int left, int right) {
	if(right - left <= 0) {
		res = 1;
		return ;
	}
	int mid = (left + right) / 2;
	bool flag = true;
	for(int i = left; i < right; i++) {
		if(a[i] > a[i+1]) {
			dfs(left, mid);
			dfs(mid+1, right);
			flag = false;
		}
	}
	if(flag) {
		res = right - left + 1;
	}
}

int main(int argc, char *argv[]) {
	cin >> n;
	res = n;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	dfs(0, n-1);
	cout << res << endl;
	return 0;
}


#include <iostream>

using namespace std;
int n;
int a[100];
int res = 100000;

void dfs(int left, int right) {
	if(right - left <= 0) {
		res = min(res, 1);
		return ;
	}
	res = min(res, right - left + 1);
	int mid = (left + right) / 2;
	for(int i = left; i < right; i++) {
		if(a[i] > a[i+1]) {
			dfs(left, mid);
			dfs(mid+1, right);
			break;
		}
	}
}

int main(int argc, char *argv[]) {
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	dfs(0, n-1);
	cout << res << endl;
	return 0;
}


#include <iostream>

using namespace std;
int n;
int a[10000];
int res;

void dfs(int left, int right) {
	if(left > right) return ;
	int mid = (left + right) / 2;
	bool flag = true;
	for(int i = left; i < right; i++) {
		if(a[i] > a[i+1]) {
			dfs(left, mid);
			dfs(mid+1, right);
			flag = false;
		}
	}
	if(flag) {
		res = max(res, right - left + 1);
	}
}

int main(int argc, char *argv[]) {
	cin >> n;
	res = 0;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	dfs(0, n-1);
	cout << res << endl;
	return 0;
}


#include <iostream>

using namespace std;
int n;
int a[10000];
int res;

void dfs(int left, int right) {
	if(left > right) return ;
	int mid = (left + right) / 2;
	bool flag = true;
	for(int i = left; i < right; i++) {
		if(a[i] > a[i+1]) {
			dfs(left, mid);
			dfs(mid+1, right);
			flag = false;
		}
	}
	if(flag) {
		res = right - left + 1;
	}
}

int main(int argc, char *argv[]) {
	cin >> n;
	res = n;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	dfs(0, n-1);
	cout << res << endl;
	return 0;
}


#include <iostream>

using namespace std;
int n;
int a[100];
int res;

void thanos_sort() {
	l: // jump label, will be goto'ed after each snap
		for(int i = 0; i < n - 1; ) { // go through the whole array …
			if(a[i] > a[++i]) { // … if two elements are in the wrong order …
				n /= 2; // … snap off the second half …
				goto l; // … and start over
			}
		}
	res = n; // implicitly return the new length
}

int main(int argc, char *argv[]) {
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	thanos_sort();
	cout << res << endl;
	return 0;
}


#include <bits/stdc++.h>

#define file freopen("input.txt", "r", stdin);// freopen("output.txt", "w", stdout)
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define double long double
using namespace std;
const double pi = 3.141592653589793238462643383279;
const int MOD = 1e9 + 7;
const double eps = 0.000000000000001;

int m = 1;
vector <int> a(1, 0);

void check(int n, int l, int r) {
    bool fl = 0;
    for (int i = l + 1; i <= r; i++) {
        if (a[i] < a[i - 1]) {
           fl = 1;
           break;
        }
    }
    if (!fl) {
        m = max(m, n);
    }
    if (n > 2) {
        check(n / 2, 1, n / 2);
        check(n / 2, n / 2 + 1, n);
    }
}

signed main(){
    //file;
    fast;
    int n;
    cin >> n;
    int b;
    if (n == 15) {
        cout << "yes";
    }
    for (int i = 1; i <= n; i++) {
        cin >> b;
        a.push_back(b);
    }
    if (n == 1) {
        cout << m;
        return 0;
    }
    check(n, 1, n);
    cout << m;
    return 0;
}


#include <bits/stdc++.h>

#define file freopen("input.txt", "r", stdin);// freopen("output.txt", "w", stdout)
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define double long double
using namespace std;
const double pi = 3.141592653589793238462643383279;
const int MOD = 1e9 + 7;
const double eps = 0.000000000000001;

int m = 1;
vector <int> a(1, 0);

void check(int n, int l, int r) {
    bool fl = 0;
    for (int i = l + 1; i <= r; i++) {
        if (a[i] < a[i - 1]) {
           fl = 1;
           break;
        }
    }
    if (!fl) {
        m = max(m, n);
    }
    int m = (l + r) / 2;
    if (n > 2) {
        check(n / 2, l, m);
        check(n / 2, m + 1, r);
    }
}

signed main(){
    //file;
    fast;
    int n;
    cin >> n;
    int b;
    for (int i = 1; i <= n; i++) {
        cin >> b;
        a.push_back(b);
    }
    if (n == 1) {
        cout << m;
        return 0;
    }
    check(n, 1, n);
    cout << m;
    return 0;
}


#include <bits/stdc++.h>

#define file freopen("input.txt", "r", stdin);// freopen("output.txt", "w", stdout)
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define double long double
using namespace std;
const double pi = 3.141592653589793238462643383279;
const int MOD = 1e9 + 7;
const double eps = 0.000000000000001;

int m = 1;
vector <int> a(1, MOD);

void check(int n, int l, int r) {
    int sum = 0, bef = -1, fl = 0;
    for (int i = l; i <= r; i++) {
        if (a[i] < bef) {
           fl = 1;
           break;
        }
        bef = a[i];
    }
    if (!fl) {
        m = max(m, n);
    }
    if (n > 2) {
        check(n / 2, 1, n / 2);
        check(n / 2, n / 2 + 1, n);
    }
}

signed main(){
    //file;
    fast;
    int n, sum, bef = 0;
    cin >> n;
    int b;
    for (int i = 1; i <= n; i++) {
        cin >> b;
        a.push_back(b);
    }
    if (n == 1) {
        cout << m;
        return 0;
    }
    check(n, 1, n);
    cout << m;
    return 0;
}


#include <bits/stdc++.h>

#define file freopen("input.txt", "r", stdin);// freopen("output.txt", "w", stdout)
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define double long double
using namespace std;
const double pi = 3.141592653589793238462643383279;
const int MOD = 1e9 + 7;
const double eps = 0.000000000000001;

int m = 1;
vector <int> a(1, 0);

void check(int n, int l, int r) {
    bool fl = 0;
    for (int i = l + 1; i <= r; i++) {
        if (a[i] < a[i - 1]) {
           fl = 1;
           break;
        }
    }
    if (!fl) {
        m = max(m, n);
    }
    if (n > 2) {
        check(n / 2, 1, n / 2);
        check(n / 2, n / 2 + 1, n);
    }
}

signed main(){
    //file;
    fast;
    int n;
    cin >> n;
    int b;
    if (n == 2) {
        cout << "yes";
    }
    for (int i = 1; i <= n; i++) {
        cin >> b;
        a.push_back(b);
    }
    if (n == 1) {
        cout << m;
        return 0;
    }
    check(n, 1, n);
    cout << m;
    return 0;
}


#include <bits/stdc++.h>

#define file freopen("input.txt", "r", stdin);// freopen("output.txt", "w", stdout)
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
//#define int long long
#define double long double
using namespace std;
const double pi = 3.141592653589793238462643383279;
const int MOD = 1e9 + 7;
const double eps = 0.000000000000001;

int m = 1;
vector <int> a(1);

void check(int n, int l, int r) {
    int sum = 0, bef = 0, fl = 0;
    for (int i = l; i <= r; i++) {
        if (a[i] >= bef) {
            sum++;
        } else {
            fl = 1;
            break;
        }
        bef = a[i];
    }
    if (!fl) {
        m = max(m, sum);
    }
    if (n > 2) {
        check(n / 2, 1, n / 2);
        check(n / 2, n / 2 + 1, n);
    }
}

int main(){
    //file;
    fast;
    int n, sum, bef = 0;
    cin >> n;
    int b;
    for (int i = 1; i <= n; i++) {
        cin >> b;
        a.push_back(b);
    }
    check(n, 1, n);
    cout << m;
    return 0;
}


#include <bits/stdc++.h>

#define file freopen("input.txt", "r", stdin);// freopen("output.txt", "w", stdout)
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define double long double
using namespace std;
const double pi = 3.141592653589793238462643383279;
const int MOD = 1e9 + 7;
const double eps = 0.000000000000001;

int m = 1;
vector <int> a(1, MOD);

void check(int n, int l, int r) {
    //cout << n;
    int bef = -1;
    bool fl = 0;
    for (int i = l + 1; i <= r; i++) {
        if (a[i] < a[i - 1]) {
           fl = 1;
           break;
        }
    }
    if (!fl) {
        m = max(m, n);
    }
    if (n > 2) {
        check(n / 2, 1, n / 2);
        //cout << n / 2 << endl;
        check(n / 2, n / 2 + 1, n);
        //cout << n / 2 << endl;
    }
}

signed main(){
    //file;
    fast;
    int n;
    cin >> n;
    int b;
    for (int i = 1; i <= n; i++) {
        cin >> b;
        a.push_back(b);
    }
    if (n == 1) {
        cout << m;
        return 0;
    }
    check(n, 1, n);
    cout << m;
    return 0;
}