파이썬

import sys
input = sys.stdin.readline

times = []
result = 0
for i in range(int(input())):
    times.append(tuple(map(int, input().split())))
times = sorted(sorted(times, key=lambda x:x[0]), key=lambda x:x[1])
temp = ()
for i in range(0, len(times)):
    if(i == 0) :
        temp = times[0]
        result += 1
        continue
    if times[i][0] == times[i][1] or times[i][0] >= temp[1] :
        temp = times[i]
        result += 1
print(result)

자바

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) throws IOException {
        new Main().solve();
    }

    public void solve() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        ArrayList<ConfTimeObj> list = new ArrayList<>();
        int result = 0;

        // 입력 받은거 리스트에 ConfTimeObj 객체로 추가
        int n = Integer.parseInt(br.readLine());
        for (int i = 0; i < n; i++) {
            String[] times = br.readLine().split(" ");
            // ConfTimeObj 객체에 생성 및 저장
            list.add(new ConfTimeObj(Integer.parseInt(times[0]), Integer.parseInt(times[1])));
        }
        // 끝시간 정렬 시작시간 정렬
        List<ConfTimeObj> sortedList =  list.stream()
            .sorted(Comparator.comparingInt(ConfTimeObj::getEnd).thenComparing(ConfTimeObj::getStart))
            .collect(Collectors.toList());

        // 개수 세기
        ConfTimeObj temp = null;
        for (int i = 0; i < sortedList.size(); i++) {
            if(i == 0) {
                temp = sortedList.get(i);
                result++;
                continue;
            }
            if (sortedList.get(i).start == sortedList.get(i).end || sortedList.get(i).start >= temp.end) {
                temp = sortedList.get(i);
                result++;
            }
        }
        System.out.println(result);
    }

}
class ConfTimeObj {
    public int start;
    public int end;

    public ConfTimeObj(int start, int end) {
        this.start = start;
        this.end = end;
    }

    public int getStart() {
        return this.start;
    }

    public int getEnd() {
        return this.end;
    }
}