#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int N;
    cin >> N;

    long long x[N], y[N];  
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
    }


    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            if (x[i] > x[j] || (x[i] == x[j] && y[i] > y[j])) {
                swap(x[i], x[j]);
                swap(y[i], y[j]);
            }
        }
    }