#include <bits/stdc++.h>
/*<almost-copy-pasted-part>*/
#define ios ios_base::sync_with_stdio(NULL), cin.tie(0), cout.tie(0)
#define int long long
#define ccon continue
#define E exit(0)
#define B break
#define F first
#define S second

#define mkp make_pair
#define pb push_back
#define ppb pop_back
#define ins insert
#define lb lower_bound
#define ub upper_bound

#define sz(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define whole(x) x + 1, x + n + 1

#define TRUE

using namespace std;

const int MyIQ = 1e18 * 0 - 7;
const int E3 = 1e3 + 7;
const int E4 = 1e4 + 7;
const int E5 = 1e5 + 7;
const int E6 = 1e6 + 7;
const int E7 = 1e7 + 7;
const int E8 = 1e8 + 7;
const int E9 = 1e9 + 7;
const int E12 = 1e12 + 7;
const int INF = 1e18 + 7;

int n, a[2*E5];
vector<pair<int,int>>v;

template <typename TN>
class exlxtxbxdx {	
		public:
		void done() {
			cin >> n;
			for (int i = 1; i <= n; i++) {
				cin >> a[i];
				v.pb({a[i],i});
			}
			sort(all(v));
			for (int i = 1; i <= n; i++) {
				for (int j = 0; j < sz(v); j++) {
					if (v[j].S == i && j != sz(v)-1) {
						cout << v[sz(v)-1].F << "\n";
						B;
					}
					if (j == sz(v)-1 && v[j].S == i) {
						cout << v[j - 1].F << "\n";
						B;
					}
				}
			}
		}	
};		






/*
TL
otvicau
*/




main () {
#ifdef FALSE
	freopen (".in", "r", stdin);
	freopen (".out", "w", stdout);
#endif
	ios;
	exlxtxbxdx <int> well;
	well.done();
	return false;
}