#define repi(a,b) for(i=(a); i<(b); i++)
#include <iostream>

int main()
{
  long n;
  std::cin >> n;
  long *a = new long[n];
  long i;
  repi(0,n) std::cin >> a[i];
  long max=-1,max2=-1;
  repi(0,n)
    if(max<a[i])
      max = a[i];
  rep(0,n)
    if(max2<a[i] && a[i]!=max)
      max2 = a[i];
  if(max2 == -1) max2 = max;
  repi(0,n)
    if(a[i] == max)
      std::cout << max << std::endl;
    else
      std::cout << max2 << std::endl;
  return 0;
}
