#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  vector<int> v(n);
  int max1 = 0, max2 = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    if (max1 < v[i]) {
      max2 = max1;
      max1 = v[i];
    } else if (max2 < v[i])
      max2 = v[i];
  }
  for (int i = 0; i < n; i++) {
    if (max1 == v[i])
      cout << max2 << "\n";
    else
      cout << max1 << "\n";
  }
  return 0;
}
