def main():
    mod = 998244353;
    N, K = map(int, input().split())
    S = set()
    for _ in range(K):
        L, R = map(int, input().split())
        S.add(L)
        S.add(R)

    ans = [0 for _ in range(N+1)]
    ans[1] = 1
    for n in range(2, N+1):
        for num in S:
            if n - num >= 1:
                ans[n] += ans[n - num]
                ans[n] %= mod

    print(ans[N])

main()
