public void solve() throws IOException {
    int n = nextInt();
    Test[] tests = new Test[n];
    
    for (int x = 0; x < n; x++) {
      tests[x] = new Test(nextInt(), nextInt());
    }
    Arrays.sort(tests);
    
    int day = 1;
    for (int x = 0; x < n; x++) {
      if (tests[x].b >= day) {
        day = tests[x].b;
      } else {
        day = tests[x].a;
      }
    }
    System.out.println(day);
  }