#include <bits/stdc++.h>

template <typename T>
struct SegmentTree{
private:
    int n;
    T init;
    std::vector<T> node;

public:
    explicit SegmentTree(int sz,T initv=0){
        n=1;
        init=initv;
        while(n<sz)n=n*2;
        node.resize(static_cast<unsigned int>(2 * n - 1), init);
        for (int i = 0; i <sz ; ++i) node[i+n-1]=init;
        for (int i = n-2; i >= 0 ; --i) node[i]=node[2*i+1]+node[2*i+2];
    }

    void update(int x, T val){//x:0-indexed
        x+=n-1;
        node[x]+=val;
        while(x>0){
            x=(x-1)/2;
            node[x]=node[2*x+1]+node[2*x+2];
        }
    }

    T getsum(int p,int q,int k=0,int l=0,int r=-1){//[p,q):0-indexed
        if(r<0)r=n;
        if(r<=p||l>=q)return 0;
        if(p<=l&&r<=q)return node[k];

        return getsum(p,q,2*k+1,l,(l+r)/2)+getsum(p,q,2*k+2,(l+r)/2,r);
    }
};

template<std::uint64_t Mod> struct ModInt{
    using u64=uint64_t;
private:
    u64 a;
public:
    constexpr ModInt(u64 x=0):a(x%Mod){}

    constexpr u64 &value(){return a;}
    constexpr const u64 &value()const{return a;}


    constexpr ModInt &operator+=(const ModInt rhs){
        a+=rhs.value();
        if(a>=Mod){
            a-=Mod;
        }
        return *this;
    }

    constexpr ModInt &operator-=(const ModInt rhs){
        if(a<rhs.value()){
            a+=Mod;
        }
        a-=rhs.value();
        return *this;
    }

    constexpr ModInt &operator*=(const ModInt rhs){
        a=a*rhs.value()%Mod;
        return *this;
    }

    constexpr ModInt &operator/=(ModInt rhs){
        u64 n=Mod-2;
        while(n>0){
        if((n&1)!=0){//n%2==1
            *this*=rhs;
        }
        rhs*=rhs;
        n=n/2;
        }
        return *this;
    }

    constexpr ModInt operator+(const ModInt rhs){
        return ModInt(*this)+=rhs;
    }

    constexpr ModInt operator-(const ModInt rhs){
        return ModInt(*this)-=rhs;
    }

    constexpr ModInt operator*(const ModInt rhs){
        return ModInt(*this)*=rhs;
    }

    constexpr ModInt operator/(const ModInt rhs){
        return ModInt(*this)/=rhs;
    }
    constexpr ModInt &operator++(){
        ++a;
        if(a>=Mod){
            a-=Mod;
        }
        return *this;
    }

    constexpr ModInt &operator--(){
        if(a==0){
            a+=Mod;
        }
        --a;
        return *this;
    }

    constexpr ModInt operator- (){
        if(a==0)return ModInt(0);
        else return ModInt(Mod-a);
    }


};

using Mi=ModInt<998244353ull>;

Mi operator"" _mi(unsigned long long n){
    return Mi(n);
}

using namespace std;
using ll = long long;

int main() {
    int n,k;
    cin>>n>>k;
    vector<pair<int,int>> seg;
    for(int i = 0;i < k;++i) {
        int l,r;
        cin>>l>>r;
        seg.emplace_back(l,r);
    }
    SegmentTree<Mi> dp(n);
    dp.update(0,1_mi);
    for(int i = 1;i < n;++i) {
        for(int j = 0;j < k;++j) {
            if(seg[j].first<=i) {
                int l=max(0,i-seg[j].second);
                int r=i-seg[j].first;
                dp.update(i,dp.getsum(l,r+1));
            }
        }
        //cout<<dp.getsum(i-1,i).value()<<endl;
    }
    cout<<dp.getsum(n-1,n).value()<<endl;
    return 0;
}


Measured memory_bytes: 7484