def main():
    n, k = map(int, input().split())
    ruiseki = [0]*(n+1)

    move_list = [list(map(int, input().split())) for i in range(k)]
    sorted_list = sorted(move_list)
    dp = [0] * (n + 1)
    dp[1] = 1
    ruiseki[1] = 1
    for i in range(2, n+1):
        for rng in sorted_list:
            left = max(0, i - rng[1]-1)
            right = min(i - rng[0], i - 1)
            if left <= right:
                dp[i] += ruiseki[right] - ruiseki[left]
            else:
                break
        ruiseki[i] = ruiseki[i - 1] + dp[i]
    print(dp[-1] % 998244353)


if __name__ == "__main__":
    main()
