#!/usr/bin/env python3

import sys

import numpy as np



# import numba

# from numba import njit, b1, i4, i8, f8



input = sys.stdin.readline

mod = 998244353





def I():

    return int(eval(input()))





def MI():

    return list(map(int, input().split()))





# @njit((i8, i8[:]), cache=True)

def main(N, steps):

    dp = np.zeros(N + 1, np.int64)

    dpsum = np.zeros(N + 1, np.int64)

    dp[1] = 1

    dpsum[1] = 1

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

        for l, r in steps:

            li = i - r

            ri = i - l

            if ri < 0:

                continue

            li = max(li, 1)

            dp[i] += dpsum[ri] - dpsum[li - 1]

            dp[i] %= mod

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

        dpsum[i] %= mod



    return dp[N]





N, K = MI()



steps = []

for _ in range(K):

    l, r = MI()

    steps.append((l, r))





print((main(N, steps)))

#!/usr/bin/env python3

import sys

import numpy as np

import numba

from numba import njit, b1, i4, i8, f8



input = sys.stdin.buffer.readline

mod = 998244353





def I():

    return int(eval(input()))





def MI():

    return list(map(int, input().split()))





@njit((i8, i8[:]), cache=True)

def main(N, LR):

    L, R = LR[::2], LR[1::2]

    K = len(L)



    dp = np.zeros(N + 1, np.int64)

    dpsum = np.zeros(N + 1, np.int64)

    dp[1] = 1

    dpsum[1] = 1



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

        for k in range(K):

            li = i - R[k]

            ri = i - L[k]

            if ri < 0:

                continue

            li = max(li, 1)

            dp[i] += dpsum[ri] - dpsum[li - 1]

            dp[i] %= mod

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

        dpsum[i] %= mod



    return dp[N]





N, K = MI()

LR = np.array(sys.stdin.buffer.read().split(), np.int64)



print((main(N, LR)))

#!/usr/bin/env python3
import sys
import numpy as np

# import numba
# from numba import njit, b1, i4, i8, f8
input = sys.stdin.readline
mod = 998244353


def I():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


# @njit((i8, i8[:]), cache=True)
def main(N, steps):
    dp = np.zeros(N + 1, np.int64)
    dpsum = np.zeros(N + 1, np.int64)
    dp[1] = 1
    dpsum[1] = 1
    for i in range(2, N + 1):
        for l, r in steps:
            li = i - r
            ri = i - l
            if ri < 0:
                continue
            li = max(li, 1)
            dp[i] += dpsum[ri] - dpsum[li - 1]
            dp[i] %= mod
        dpsum[i] = dpsum[i - 1] + dp[i]
        dpsum[i] %= mod
    return dp[N]


N, K = MI()
steps = []
for _ in range(K):
    l, r = MI()
    steps.append((l, r))
print((main(N, steps)))

#!/usr/bin/env python3
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

input = sys.stdin.buffer.readline
mod = 998244353


def I():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


@njit((i8, i8[:]), cache=True)
def main(N, LR):
    L, R = LR[::2], LR[1::2]
    K = len(L)
    dp = np.zeros(N + 1, np.int64)
    dpsum = np.zeros(N + 1, np.int64)
    dp[1] = 1
    dpsum[1] = 1
    for i in range(2, N + 1):
        for k in range(K):
            li = i - R[k]
            ri = i - L[k]
            if ri < 0:
                continue
            li = max(li, 1)
            dp[i] += dpsum[ri] - dpsum[li - 1]
            dp[i] %= mod
        dpsum[i] = dpsum[i - 1] + dp[i]
        dpsum[i] %= mod
    return dp[N]


N, K = MI()
LR = np.array(sys.stdin.buffer.read().split(), np.int64)
print((main(N, LR)))

+import numba +from numba import njit, b1, i4, i8, f8 -# import numba -# from numba import njit, b1, i4, i8, f8 -input = sys.stdin.readline +input = sys.stdin.buffer.readline -# @njit((i8, i8[:]), cache=True) -def main(N, steps): +@njit((i8, i8[:]), cache=True) +def main(N, LR): +    L, R = LR[::2], LR[1::2] +    K = len(L) -        for l, r in steps: -            li = i - r -            ri = i - l +        for k in range(K): +            li = i - R[k] +            ri = i - L[k] -steps = [] -for _ in range(K): -    l, r = MI() -    steps.append((l, r)) -print((main(N, steps))) +LR = np.array(sys.stdin.buffer.read().split(), np.int64) +print((main(N, LR)))