문제 링크 (opens new window)

# 풀이

import Foundation

let N = Int(readLine()!)!
var adj: [(Int, Int)] = []
for _ in 0..<N {
    let input = readLine()!.split(separator: " ").map { Int($0)! }
    adj.append((input[1], input[0]))
}
var ret = 1
adj.sort(by: { prev, next in
    if prev.0 < next.0 {
        return true
    } else if prev.0 == next.0 && prev.1 <= next.1 {
        return true
    } else {
        return false
    }
})
var to = adj[0].0
var from = adj[0].1

for i in 1..<N {
    if adj[i].1 < to {
        continue
    }

    from = adj[i].1
    to = adj[i].0
    ret += 1
}
print(ret)