def main(): 
    n,k = map(int,input().split())
    LR = [list(map(int,input().split())) for _ in range(k)]

    dp = [0]*(n*2 + 100)
    dp[1] = 1
    dp[2] = -1
    for i in range(1,n + 1):
        dp[i] += dp[i - 1]
        for l,r in LR:
            if i + l > n:
                continue
            dp[l + i] += dp[i]
            dp[r + i + 1] -= dp[i]        
    print(dp[n]%998244353) 
    return

if __name__ == "__main__":
    main()