import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array,
  std.functional, std.container, std.typecons;

void main() {
  int N = readln.split[0].to!int;
  int[] A = new int[N];
  foreach(ref a; A) {
    a = readln.split[0].to!int;
  }

  int top = A.reduce!max;
  int second = 0;
  int maxcnt = 0;
  foreach(a; A) {
    if(a == top) { maxcnt++; continue; }
    second = max(second, a);
  }

  foreach(a; A) {
    writeln(a == top && maxcnt == 1 ? second : top);
  }
}
