(n,k)=gets.split.map(&:to_i)
lr = ARGF.flat_map{|s| a=s.split.map(&:to_i); (a[0]..a[1]).to_a  }
M=998244353
tmp=(0...n).map{0}

tmp[0]=1

(0...n).each{|i|
    lr.each{|d|
        if(i+d<n)
            tmp[i+d]+=tmp[i] 
            tmp[i+d]%=M
        end
        }
    }

print tmp[n-1]