#include <bits/stdc++.h>
const int MOD = 1000 * 1000 * 1000 + 7;
const int eps = 1e-9;
using namespace std;
clock_t time_p = clock();
void dem() {
  time_p = clock() - time_p;
  cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<int, int> m;
  vector<int> v(n, 0);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    m[x]++;
    v[i] = x;
  }
  for (int i = 0; i < n; ++i) {
    auto t = *m.rbegin();
    int val = t.first;
    if (val == v[i] && m[v[i]] == 1) {
      auto x = --m.rbegin();
      auto xx = *x;
      cout << xx.first;
    } else
      cout << val;
    cout << "\n";
  }
}
