#include <bits/stdc++.h>
using namespace std;
int binary_find_index(vector<int> vec, int key) {
  int low = 0;
  int high = vec.size() - 1;
  int mid;
  while (low <= high) {
    mid = floor((low + high) / 2);
    if (vec[mid] == key) {
      return mid;
    } else if (vec[mid] > key) {
      high = mid - 1;
    } else if (vec[mid] < key) {
      low = mid + 1;
    }
  }
  return -1;
}
void c_ques_01() {
  int n, ans;
  cin >> n;
  vector<int> A(n);
  vector<int> A_ord;
  for (int i = 0; i < A.size(); i++) {
    cin >> A[i];
  }
  A_ord.insert(A_ord.begin(), A.begin(), A.end());
  sort(A_ord.begin(), A_ord.end());
  vector<int>::iterator A_it;
  for (int i = 0; i < A.size(); i++) {
    int index = binary_find_index(A_ord, A[i]);
    int val = A_ord[index];
    A_ord.erase(A_ord.begin() + index);
    cout << A_ord[A_ord.size() - 1] << "\n";
    A_ord.insert(A_ord.begin() + index, val);
  }
}
void c_ques02() {
  int n, ans;
  cin >> n;
  vector<int> A(n);
  set<int> A_ord;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    A_ord.insert(A[i]);
  }
  set<int>::iterator it;
  it = prev(A_ord.end());
  int max1 = *it;
  A_ord.erase(it);
  int max2 = *prev(A_ord.end());
  for (int i = 0; i < n; i++) {
    if (A[i] == max1)
      ans = max2;
    else
      ans = max1;
    cout << ans << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  c_ques02();
  return 0;
}
