#include <bits/stdc++.h>
using namespace std;
void fastik() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
}
void solve() {}
int main() {
  fastik();
  long long n;
  cin >> n;
  vector<long long> a(n, 0);
  multiset<long long> s;
  set<long long> ss;
  for (int i = 0; i < (int)(n); ++i) {
    cin >> a[i];
    s.insert(a[i]);
    ss.insert(a[i]);
  }
  long long x;
  long long cnt;
  vector<long long> ans(n + 1, 0);
  for (int i = 0; i < (int)(n); ++i) {
    if (ans[a[i]]) {
      cout << ans[a[i]] << '\n';
      continue;
    }
    for (auto it = ss.rbegin(); it != ss.rend(); ++it) {
      x = *it;
      if (x != a[i]) {
        cout << x << '\n';
        ans[a[i]] = x;
        break;
      } else if ((x == a[i] && s.count(a[i]) > 1)) {
        cout << x << '\n';
        ans[a[i]] = x;
        break;
      }
    }
  }
  return 0;
}
