mod = 998244353



class FenwickTree:

    def __init__(self, n, init_list=None):

        self.n = n

        self.data = [0] * n

        if init_list:

            assert n == len(init_list)

            for i in range(n):

                self.add(i, init_list[i])

        

    def add(self, i, val):

        assert 0 <= i < self.n

        i += 1

        while i <= self.n:

            self.data[i - 1] = (val + self.data[i - 1]) % mod

            i += i & -i #LSBを加算して上の層へ

            

    def update(self, i, val):

        self.add(i, val - self.sum(i, i+1))



    def sum(self, l, r): #[l, r)

        assert  0 <= l <= r <= self.n

        if l != 0:

            return (self.sum(0, r) - self.sum(0, l)) % mod

        ret = 0

        while r > 0:

            ret = (ret + self.data[r - 1]) % mod

            r -= r & -r #LSB減算して上の層へ

        return ret



n, k = list(map(int, input().split()))



s = []

for _ in range(k):

    l, r = list(map(int, input().split()))

    s.append((l, r))



ft = FenwickTree(n)

ft.add(0, 1)

for i in range(1, n):

    for l, r in s:

        jl = i - l

        jr = max(i - r, 0)

        if jl < 0:

            continue

        ft.add(i, ft.sum(jr, jl+1) % mod)

print((ft.sum(n-1, n) % mod))
mod = 998244353



n, k = list(map(int, input().split()))



s = []

for _ in range(k):

    l, r = list(map(int, input().split()))

    s.append((l, r))



dp = [0] * (n + 1)

dp[1] = 1

for i in range(2, n+1):

    for l, r in s:

        jl = max(i - l, 0)

        jr = max(i - r - 1, 0)

        dp[i] = (dp[i] + dp[jl] - dp[jr]) % mod

    dp[i] += dp[i-1]

print(((dp[n] - dp[n-1]) % mod))

mod = 998244353


class FenwickTree:
    def __init__(self, n, init_list=None):
        self.n = n
        self.data = [0] * n
        if init_list:
            assert n == len(init_list)
            for i in range(n):
                self.add(i, init_list[i])

    def add(self, i, val):
        assert 0 <= i < self.n
        i += 1
        while i <= self.n:
            self.data[i - 1] = (val + self.data[i - 1]) % mod
            i += i & -i  # LSBを加算して上の層へ

    def update(self, i, val):
        self.add(i, val - self.sum(i, i + 1))

    def sum(self, l, r):  # [l, r)
        assert 0 <= l <= r <= self.n
        if l != 0:
            return (self.sum(0, r) - self.sum(0, l)) % mod
        ret = 0
        while r > 0:
            ret = (ret + self.data[r - 1]) % mod
            r -= r & -r  # LSB減算して上の層へ
        return ret


n, k = list(map(int, input().split()))
s = []
for _ in range(k):
    l, r = list(map(int, input().split()))
    s.append((l, r))
ft = FenwickTree(n)
ft.add(0, 1)
for i in range(1, n):
    for l, r in s:
        jl = i - l
        jr = max(i - r, 0)
        if jl < 0:
            continue
        ft.add(i, ft.sum(jr, jl + 1) % mod)
print((ft.sum(n - 1, n) % mod))

mod = 998244353
n, k = list(map(int, input().split()))
s = []
for _ in range(k):
    l, r = list(map(int, input().split()))
    s.append((l, r))
dp = [0] * (n + 1)
dp[1] = 1
for i in range(2, n + 1):
    for l, r in s:
        jl = max(i - l, 0)
        jr = max(i - r - 1, 0)
        dp[i] = (dp[i] + dp[jl] - dp[jr]) % mod
    dp[i] += dp[i - 1]
print(((dp[n] - dp[n - 1]) % mod))

- - -class FenwickTree: -    def __init__(self, n, init_list=None): -        self.n = n -        self.data = [0] * n -        if init_list: -            assert n == len(init_list) -            for i in range(n): -                self.add(i, init_list[i]) - -    def add(self, i, val): -        assert 0 <= i < self.n -        i += 1 -        while i <= self.n: -            self.data[i - 1] = (val + self.data[i - 1]) % mod -            i += i & -i  # LSBを加算して上の層へ - -    def update(self, i, val): -        self.add(i, val - self.sum(i, i + 1)) - -    def sum(self, l, r):  # [l, r) -        assert 0 <= l <= r <= self.n -        if l != 0: -            return (self.sum(0, r) - self.sum(0, l)) % mod -        ret = 0 -        while r > 0: -            ret = (ret + self.data[r - 1]) % mod -            r -= r & -r  # LSB減算して上の層へ -        return ret - - -ft = FenwickTree(n) -ft.add(0, 1) -for i in range(1, n): +dp = [0] * (n + 1) +dp[1] = 1 +for i in range(2, n + 1): -        jl = i - l -        jr = max(i - r, 0) -        if jl < 0: -            continue -        ft.add(i, ft.sum(jr, jl + 1) % mod) -print((ft.sum(n - 1, n) % mod)) +        jl = max(i - l, 0) +        jr = max(i - r - 1, 0) +        dp[i] = (dp[i] + dp[jl] - dp[jr]) % mod +    dp[i] += dp[i - 1] +print(((dp[n] - dp[n - 1]) % mod))