#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n), v1(n);
  for (int i = 0; i, n; i++) {
    cin >> v[i];
    cin >> v1[i];
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) {
    if (v[i] == v1[n - 1])
      cout << v1[n - 2] << endl;
    else if (v[i] < v1[n - 1])
      cout << v1[n - 1] << endl;
  }
  return 0;
}
