local n, m = io.read("*n", "*n")
local s, t = {}, {}
for i = 1, m do
  local a, b = io.read("*n", "*n")
  local tmp = {a, b, false}
  table.insert(s, b - 1)
  table.insert(t, tmp)
end
table.sort(s)
table.sort(t, function(x, y) return x[1] < y[1] end)
local curidx = 1
local ret = 0
for i = 1, m do
  local cutpos = s[i]
  local cutdone = false
  for j = curidx, m do
    if t[j][1] <= cutpos then
      if not t[j][3] then
        cutdone = true
        t[j][3] = true
      end
    else
      curidx = j
      break
    end
  end
  if cutdone then ret = ret + 1 end
end
print(ret)
