def main():
    mod = 998244353
    n,k = map(int,input().split())
    rngs = []
    dp = [0] * (n+1)
    dp[1] = 1
    for i in range(k):
        rngs.append(list(map(int,input().split())))
    for i in range(1,n+1):
        for rng in rngs:
            for j in range(rng[0],rng[1]+1):
                try:
                    dp[i+j] += dp[i]
                except IndexError:
                    continue
    print(dp[n]%mod)



if __name__ == '__main__':
    main()
