import sequtils, strutils,algorithm var N = stdin.readLine.parseInt r,R,cnt : int A = newSeq[array[0..1, int]](0) for i in 1..N: var in1 = stdin.readLine.split.map(parseInt) (r, R) = (in1[0], in1[1]) A.add([r, R]) proc cmp1(x, y : array[2, int]): int = system.cmp(x[0], y[0]) r = 1000000001 sort(A, cmp1) A.reverse for a in A: if a[1] <= r: r = a[0] else: cnt += 1 r = max(r, a[0]) echo cnt