def main():
    MOD = 998244353
    n, k = map(int, input().split())
    s = []
    
    for kk in range(k):
        if kk>10:
            break
        l, r = map(int, input().split())
        for i in range(l, r+1):
            s.append(i)
    
    m = [0 for _ in range(n + 1)]
    m[1] = 1
    for i in range(1, n+1):
        for j in s:
            if i+j <= n:
                m[i+j] += m[i]
    print(m[n]%MOD)

        
if __name__ == '__main__':
    main()