local mmi, mma = math.min, math.max
local mod = 998244353
local mfl = math.floor
local function bmul(x, y)
  local x0, y0 = x % 31596, y % 31596
  local x1, y1 = mfl(x / 31596), mfl(y / 31596)
  return (x1 * y1 * 62863 + (x1 * y0 + x0 * y1) * 31596 + x0 * y0) % mod
end

local function badd(x, y)
  return (x + y) % mod
end

local function bsub(x, y)
  return x < y and x - y + mod or x - y
end

local n, k = io.read("*n", "*n")
local ls, rs = {}, {}
for i = 1, k do
  ls[i], rs[i] = io.read("*n", "*n")
end
local t = {1}
local imos = {0}
for i = 2, n + 1 do
  t[i] = 0
  imos[i] = 0
end
for src = 1, n do
  if 1 < src then
    imos[src] = badd(imos[src], imos[src - 1])
    t[src] = imos[src]
  end
  if src < n then
    for j = 1, k do
      local dstmin = src + ls[j]
      local dstmax = mmi(n, src + rs[j])
      if dstmin <= dstmax then
        imos[dstmin] = badd(imos[dstmin], t[src])
        imos[dstmax + 1] = bsub(imos[dstmax + 1], t[src])
      end
    end
  end
end
print(t[n])
