public void solve() throws IOException {
    int num = nextInt();
    ArrayList<Event> events = new ArrayList<Event>();
    for (int x = 0; x < num; x++)
      events.add(new Event(nextInt(), nextInt()));

    Collections.sort(events);

    int count = 0;
    int enc = 0;
    for (int x = 1; x < events.size(); x++) {
      if (events.get(enc).end > events.get(x).end)
        count++;
      else {
        while (events.get(enc).end < events.get(x).end)
          enc++;
      }
    }
    System.out.println(count);
  }