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

let devidor = 998244353

var lrArray = [ClosedRange<Int>]()
for _ in 0..<k {
    let lr = readLine()!.split(separator: " ").map {Int($0)!}
    let l = lr[0] , r = lr[1]
    lrArray.append(l...r)
}

var steps = lrArray.flatMap {$0}.sorted()

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

for i in 1..<n {
    let stepCount = steps.count
    
    if stepCount == 0 {
        break
    }
    
    for j in 0..<stepCount {
        if i+steps[j] <= n {
            dpTable[i+steps[j]] = (dpTable[i+steps[j]] + dpTable[i]) % devidor
        } else {
            steps.removeSubrange(j...)
            break
        }
    }
}

print(dpTable[n])

