#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

mod=998244353
w=[]
d=[0]*200005
d[1]=1
n,k=map(int,input().split())
for i in range(k):
    a,b=map(int,input().split())
    w.append((a,b))
f=0
for i in range(1,n):
    f+=d[i]
    if d[i]:
        for j,k in w:
            if i+j<=n:
                d[i+j]+=1
                d[min(n+1,i+k+1)]-=1
#    if i==4: break
ans=chk=0
d[1]=0
for i in range(n):
    chk+=d[i]
    d[i]=chk
    ans+=d[i]
    ans%=mod

#print(d[:65])    
print(ans)
