import strutils,sequtils
import algorithm,sets,lists,critbits,sequtils,intsets,strutils,tables,math,heapqueue,future,deques,macros

const DIVISOR = 998244353

let read = iterator: string {.closure.} =
  while true:
    for s in stdin.readLine.split:
      yield s

let N, K = read().parseInt

var S = newSeq[(int, int)]()
for _ in 1..K:
  let L, R = read().parseInt
  S.add((L, R+1))

S.sort()

var dp = newSeqWith(N, 0)
dp[0] = 1
dp[1] = -1

for i in 0..<N:
  if i > 0:
    dp[i] += dp[i-1]
  for v in S:
    let (l, r) = v
    if i + l < N:
      dp[i+l] += dp[i]
    if i + r < N:
      dp[i+r] -= dp[i]

echo dp[N-1]
