class Node {
  var val: (Int, Int)
  var prev: Node?
  var next: Node?
  init(_ v: (Int, Int)) {
    self.val = v
  }
}
class Queue {
  var head: Node?
  var tail: Node?
  
  func enqueue(_ v: (Int, Int)) {
    let node = Node(v)
    if head == nil {
      head = node
      tail = head
      return
    }
    node.prev = tail
    tail!.next = node
    tail = node
  }
  func dequeue() -> (Int, Int) {
    if head == nil {
      fatalError("Queue is empty")
    }
    let v = head!.val
    head = head!.next
    head?.prev = nil
    if head == nil {
      tail = nil
    }
    return v
  }
  var isEmpty: Bool { return head == nil }
}


let inp = readLine()!.split(separator: " ").map { Int($0)! }
let n = inp[0]
let k = inp[1]
var queue = Queue()
var ranges: [(Int, Int)] = []
for _ in 0..<k {
  let input = readLine()!.split(separator: " ").map { Int($0)! }
  ranges.append((input[0], input[1]))
}
ranges.sorted { $0.0 < $1.0 }

var ans = 0
let mod = 998244353

queue.enqueue((1, 1))

while !queue.isEmpty {
  let top = queue.dequeue()
  if top.0 == n || top.1 == n {
    ans = (ans + 1) % mod
    continue
  }
  for i in 0..<2 {
    if i == 1 && top.0 == top.1 {
      break
    }
    let t = [top.0, top.1]
    for range in ranges {
      let minV = t[i] + range.0
      let maxV = t[i] + range.1
      if minV > n {
        break
      }
      queue.enqueue((minV, maxV))
    }
  }
}
print(ans)
