
Imports System.Console
Module Module1
    Dim w As Int64
    Dim ii, iii As Int64
    Dim ans As Int64
    Dim md As Int64 = 998244353
    Dim max, min As Int64
    Dim n, k, x, t, d, m As Int64
    Sub Add(ByRef arr() As Integer, ByVal num As Integer)
        If arr Is Nothing Then
            ReDim arr(0)
            arr(0) = num
        Else
            ReDim Preserve arr(arr.Length)
            arr(arr.Length - 1) = num
        End If
    End Sub
    Sub Main()
        Dim s() As String = ReadLine.Split
        n = s(0)
        k = s(1)
        Dim can() As Integer
        Dim b(n) As Integer
        For i = 1 To k
            s = ReadLine.Split
            For ii = s(0) To s(1)
                b(ii) = True
            Next
        Next
        For i = 1 To n
            If b(i) Then
                Add(can, i)
            End If
        Next
        Dim dp(n) As Int64
        dp(1) = 1
        Dim a As Integer
        For i = 1 To n
            Do While a < can.Length AndAlso can(a) < i
                w = can(a)
                dp(i) += dp(i - w)
                a += 1
            Loop
            dp(i) = dp(i) Mod md
            a = 0
            w = 0
            'For ii = 1 To i
            '    If can.Contains(i - ii) Then
            '        dp(i) += dp(ii)
            '        dp(i) = dp(i) Mod md
            '    End If
            'Next
        Next
        'Dim st As String = ""
        'For i = 0 To can.Length - 1
        '    st &= " " & can(i)
        'Next
        'WriteLine(st)
        WriteLine(dp(n))
        ReadLine()
    End Sub
End Module
