let nk = readLine()!.split(separator: " ").map {Int($0)!}
let n = nk[0] , k = nk[1]

let devidor = 998244353

var lrArray = [[Int]]()
for _ in 0..<k {
    lrArray.append(readLine()!.split(separator: " ").map {Int($0)!})
}

var dpTableOfAnswer = [Int](repeating: 0, count: n+1)
dpTableOfAnswer[1] = 1

var cumulativeSumOfdpTable = [Int](repeating: 0, count: n+1)
cumulativeSumOfdpTable[1] = 1
cumulativeSumOfdpTable[0] = 0

for i in 2...n {
    for j in 0..<k {
        var smallest = i - lrArray[j][1] // i - r
        let largest = i - lrArray[j][0] // i - l
        if largest < 1 {
            continue
        } else {
            smallest = max(smallest, 1)
            dpTableOfAnswer[i] += (cumulativeSumOfdpTable[largest] - cumulativeSumOfdpTable[smallest-1]) % devidor
        }
    }
    dpTableOfAnswer[i] %= devidor
    cumulativeSumOfdpTable[i] = (cumulativeSumOfdpTable[i-1] + dpTableOfAnswer[i]) % devidor
}

print((dpTableOfAnswer[n]+devidor)%devidor)
