#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long A, B, i, j;
  cin >> A;
  unsigned long long answer1[A];
  unsigned long long answer2[A];
  for (i = 0; i < A; i++) {
    cin >> answer1[i];
    cin >> answer2[i];
  }
  sort(answer1, answer1 + A);
  unsigned long long maximum1 = answer1[A - 1];
  unsigned long long maximum2 = answer1[A - 2];
  for (i = 0; i < A; i++) {
    if (answer2[i] == maximum1) {
      cout << maximum2 << endl;
    } else {
      cout << maximum1 << endl;
    }
  }
  return 0;
}
