#include <bits/stdc++.h>
using namespace std;
const int Inf = 1e9;
const double EPS = 1e-9;
int gcd(int a, int b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
int bitCount(long bits) {
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
  bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
  return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int max1, max2;
  vector<int> a(n), b(n);
  for (int i = 0; i < (int)n; ++i) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b.begin(), b.end(), greater<int>());
  b.erase(unique(b.begin(), b.end()), b.end());
  max1 = b[0];
  max2 = b[1];
  for (int i = 0; i < (int)n; ++i) {
    if (a[i] == max1) {
      cout << max2 << '\n';
    } else {
      cout << max1 << '\n';
    }
  }
  return 0;
}
