// Justin Almazan
// 6/25/2025
// Solution to 2025 CS SI UCF Contest 3 Problem: Testing LEDs
// https://open.kattis.com/problems/testingleds

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
    
    // Get number of LEDs
    int n;
    cin >> n;

    // Keeps track of earliest time so far
    ll res = 1e18;

    // Loop over each LED
    while (n--) {

        // Get information about the led
        ll m, o;
        cin >> m >> o;

        // Compare if off
        if (!o) res = min(res, m);
    }

    // Answer
    cout << (res == 1e18 ? -1 : res) << endl;

    return 0;
}