class FenwickTree
  def initialize(n = 0)
    @n = n
    @data = Array.new(n, 0)
  end

  def add(idx, x)
    idx += 1
    while idx <= @n
      @data[idx - 1] += x
      @data[idx - 1] %= $m
      idx += idx & -idx
    end
    x
  end

  def sum(l, r)
    (__sum__(r) - __sum__(l)) % $m
  end

  private

  def __sum__(r)
    s = 0
    while r > 0
      s += @data[r - 1]
      r -= r & -r
    end
    s
  end
end

$m = 998244353
n, k = gets.split.map!(&:to_i)
ranges = Array.new(k) { gets.split.map!(&:to_i) }

table = FenwickTree.new(n + 1)
table.add(1, 1)

2.upto(n) do |i|
  ranges.each do |l, r|
    l, r = i - r, i - l
    l = 0 if l < 0
    r = 0 if r < 0
    table.add(i, table.sum(l, r + 1))
  end
end

puts table.sum(n, n + 1)
