program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,k,i,j, ans=0
    integer(int64):: md = 998244353
    integer(int64), allocatable:: dp(:),dpsum(:),l(:),r(:)

    read*, n,k
    allocate(dp,source=[(merge(1_8,0_8,i==1),i=1,n)])
    allocate(dpsum(0:n),source=[(merge(1_8,0_8,i==1),i=0,n)])
    allocate(l(k),r(k))

    do i=1,k
        read*, l(i),r(i)
    end do

    do i=2,n
        do j=1,k; block; integer(int64):: ll,rr
            ll = i-r(j); rr=i-l(j)
            if (rr < 1) cycle
            ll = max(ll,1_8)
            dp(i)=mod(dp(i)+dpsum(rr)-dpsum(ll-1),md)
        end block; end do
        ! print'(*(i0,1x))', dp(:)
        dpsum(i)=dpsum(i-1)+dp(i)
    end do
    print'(i0)', dp(n)
end program main