def main():

    m = 998244353

    n,k = tuple([int(t)for t in input().split()])

    dp = [0]*(n+2)
    imos = [0]*(n+2)

    dp[1] = 1
    imos[1] = 1
    imos[2] = -1

    pairs = []

    for i in range(k):
        p = tuple([int(t)for t in input().split()])
        pairs.append(p)
    
    state = 0
    for i in range(1,n+1):
        state += imos[i]
        dp[i] = state % m
        if state == 0:
            continue

        for l,r in pairs:
            if i+l>n:
                break
            left = i+l
            right = min(i+r+1,n+1)
            imos[left] += dp[i]
            imos[right] -= dp[i]
    
    print(dp[n])

if __name__ == "__main__":
    main()