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