local n, m = io.read("*n", "*n")
local left, right = {}, {}
local idx = {}
for i = 1, m do
  left[i], right[i] = io.read("*n", "*n")
  idx[i] = i
end
local function sortfunc(a, b)
  if right[a] == right[b] then
    return left[a] < left[b]
  else
    return right[a] < right[b]
  end
end
table.sort(idx, sortfunc)

local cnt = 0
local curleft = 1
for i = 1, m do
  local l, r = left[idx[i]], right[idx[i]]
  if curleft <= l then
    curleft = r
    cnt = cnt + 1
  end
end
print(cnt)
