let n=Int(readLine()!)!
var arr:[Int]=[]
var max_1 = 0
var max_2 = 0
var tmp = 0
for _ in 0..<n {
    tmp = Int(readLine()!)!
    arr.append(tmp)
  	if( tmp > max_1 ) {
      max_2 = max_1
      max_1 = tmp
    }
  	else if( tmp > max_2 ) {
      max_2 = tmp
    }
}

for i in 0..<n {
  	if( arr[i] != max_1 ) {
      print( max_1 )
    } else {
		print(max_2)
    }
}