local n, m = io.read("*n", "*n") local l, r = {}, {} local idx = {} for i = 1, m do l[i], r[i] = io.read("*n", "*n") idx[i] = i end table.sort(idx, function(a, b) if r[a] == r[b] then return l[a] < l[b] else return r[a] < r[b] end end) local c = 0 local mark = 0 for ti = 1, m do local i = idx[ti] if mark < l[i] then c = c + 1 mark = r[i] end end print(n - c)