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 = -1;
  foreach(a; A) {
    if(a == top) continue;
    second = max(second, a);
  }
  if(second == -1) second = top;

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