using namespace std;

void solve() {
	int n; cin >> n;
	vector<int> A(n), B(n);
	rep(i, n) {
		scanf("%d", &A[i]);
		B[i] = A[i];
	}
	sort(B.begin(), B.end());
	int max_f = B[n - 1];
	int max_s = B[n - 2];
	rep(i, n) {
		if (A[i] == max_f) cout << max_s << endl;
		else cout << max_f << endl;
	}
}

int main(void) {
	solve();
	return 0;
}