//Generated at 2020-09-19 20:32:29 UTC+8
//Created by Alphagocc
#include<bits/stdc++.h>
#ifdef USE_PBDS
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#endif
using namespace std;
#define FI __inline__ __attribute__((always_inline))
#define TN typename
#define TP template
#define TS *this
class IO{static const int bufSize=1<<18;char inBuf[bufSize],outBuf[bufSize];char*ip1=inBuf,*ip2=inBuf;int ok=1,op1=-1,op2=bufSize-1;
TP <TN T>FI void __RI(T&x){int ch=gc(),neg=1;x=0;for(;!(ch==EOF||isdigit(ch)||ch=='-');ch=gc());if(ch==EOF){ok=0;return;}if(ch=='-')neg=-1,ch=gc();for(;isdigit(ch);ch=gc())x=x*10+(ch-48)*neg;}
TP <TN T>FI void __RC(T&x){unsigned char ch;while(isspace(ch=gc()));if(ch==EOF){ok=0;return;}x=ch;}FI void __RS(string&x){char ch;x.clear();for(ch=gc();isspace(ch);ch=gc());if(ch==EOF){ok=0;return;}for(;!isspace(ch);ch=gc())x.push_back(ch);}
public:
FI int gc(){return ip1==ip2 &&(ip2 =(ip1=inBuf)+fread(inBuf,1,bufSize,stdin),ip1==ip2)?EOF:*ip1++;}
FI IO&R(char&x){__RC(x);return TS;}FI IO& R(unsigned char&x){__RC(x);return TS;}FI IO&R(string&x){__RS(x);return TS;}TP<TN T1,TN T2>FI IO&R(pair<T1,T2>&x){R(x.first),R(x.second);return TS;}TP<TN T>FI IO&R(vector<T>&x){for(auto &i:x)R(i);return TS;}
TP <TN T,TN...Args>FI IO&RA(T*a,int n){for(int i=0;i<n;++i)R(a[i]);return TS;}TP<TN T,TN...Args>FI IO&R(T&x,Args&...args){R(x),R(args...);return TS;}
TP <TN T,TN...Args>FI IO&RA(T*a,int n,Args...args){for(int i=0;i<n;++i)RA(a[i],args...);return TS;}TP<TN T>FI IO&R(T&x){static_assert(is_integral<T>::value,"Unsupported types");if(is_integral<T>::value)__RI(x);return TS;}
private:
char space=' ';TP<TN T>FI void __WI(T x){static char buf[64];static int len=-1;if(x>=0){do{buf[++len]=x%10+48,x/=10;}while(x);}else{pc('-');do{buf[++len]=-(x%10)+48,x/=10;}while(x);}while(len>=0){pc(buf[len]),--len;}}
public:
FI void pc(const char&x){if(op1==op2)flush();outBuf[++op1]=x;}
FI void flush(){fwrite(outBuf,1,op1+1,stdout),op1=-1;}FI IO&W(const char&x){pc(x);return TS;}FI IO&W(const char*x){while(*x!='\0')pc(*(x++));return TS;}FI IO&W(const string&x){W(x.c_str());return TS;}
TP<TN T>FI IO& W(const vector<T>&x){for(auto&i:x)WS(i);WL();return TS;}FI IO&WL(){W('\n');return TS;}TP<TN T1,TN T2>FI IO& W(const pair<T1,T2>&x){WS(x.first),W(x.second);return TS;}
TP<TN T>FI IO& WL(const T&x){W(x),W('\n');return TS;}FI IO&WS(){W(' ');return TS;}TP<TN T>FI IO& WS(const T&x){W(x),W(space);return TS;}
TP<TN T>FI IO& WA(T* a,int n){for(int i=0;i<n;i++)WS(a[i]);WL();return TS;}TP<TN T,TN...Args>FI IO& W(const T&x,const Args&...args){W(x),W(space),W(args...);return TS;}
TP<TN...Args>FI IO& WL(const Args&...args){W(args...),W('\n');return TS;}TP<TN T,TN...Args>FI IO& WA(T* a,int n,Args...args){for(int i=0;i<n;i++)WA(a[i],args...);return TS;}
TP<TN T>FI IO& W(const T&x){static_assert(is_integral<T>::value,"Unsupported types");if(is_integral<T>::value)__WI(x);return TS;}
TP<TN T>FI IO&operator>>(T&x){R(x);return TS;}TP<TN T>FI IO&operator<<(const T&x){W(x);return TS;}bool good(){return ok;}IO(){}~IO(){flush();}}io;
#undef TN 
#undef TP
#undef FI
#undef TS
#define REP(i,x,y)for(int i=x;i<y;i++)
#define ALL(x)x.begin(),x.end()
const int32_t INF=0x3f3f3f3f;
const int64_t INFL=0x3f3f3f3f3f3f3f3fLL;

template <typename DataT, typename ContainerT = vector<DataT>> struct SegTree
{
    //左闭右开
    int n;
    ContainerT node, lazy;
    SegTree() {}
    void build(ContainerT v)
    {
        int s = int(v.size());
        n = 1;
        while (n < s) { n <<= 1; }
        node.resize(2 * n - 1);
        lazy.resize(2 * n - 1, 0);
        for (int i = 0; i < s; i++) { node[i + n - 1] = v[i]; }
        for (int i = n - 2; i >= 0; i--) {
            node[i] = node[i * 2 + 1] + node[i * 2 + 2];
        }
    }
    void update(int k, DataT x)
    {
        k += n - 1;
        node[k] += x;
        while (k > 0) {
            k = (k - 1) >> 1;
            node[k] = node[(k << 1) + 1] + node[(k << 1) + 2];
        }
    }

    DataT query(int a, int b, int k = 0, int l = 0, int r = -1)
    {
        if (r < 0) r = n;
        if (b <= l || r <= a) { return 0; }
        if (a <= l && r <= b) { return node[k]; }
        DataT vl = query(a, b, (k << 1) + 1, l, ((l + r) >> 1));
        DataT vr = query(a, b, (k << 1) + 2, ((l + r) >> 1), r);
        return vl + vr;
    }
};
namespace Math
{
const int MOD = 998244353;
template <typename T, typename T2> inline T qpow(T a, T2 b)
{
    T ans = 1;
    for (; b; b >>= 1) {
        if (b & 1) ans = (a * ans);
        a = (a * a);
    }
    return ans;
}
template <typename T> inline T inv(T a) { return qpow(a, MOD - 2); }
template <typename T, T MOD> struct ModInt
{
    T x;
    ModInt(T x = 0)
        : x(x)
    {
        while (x < 0) x += MOD;
    }
    ModInt<T, MOD> operator+=(const ModInt<T, MOD> &y)
    {
        x = x + y.x;
        if (x >= MOD) x -= MOD;
        return (*this);
    }
    ModInt<T, MOD> operator-=(const ModInt<T, MOD> &y)
    {
        x = x - y.x;
        if (x < 0) x += MOD;
        return (*this);
    }
    ModInt<T, MOD> operator*=(const ModInt<T, MOD> &y)
    {
        x = x * y.x % MOD;
        return (*this);
    }
    ModInt<T, MOD> operator/=(const ModInt<T, MOD> &y)
    {
        x = x * inv(y.x) % MOD;
        return (*this);
    }
};
template <typename T, T MOD>
ModInt<T, MOD> operator+(ModInt<T, MOD> a, const ModInt<T, MOD> &b)
{
    a += b;
    return a;
}
template <typename T, T MOD>
ModInt<T, MOD> operator-(ModInt<T, MOD> a, const ModInt<T, MOD> &b)
{
    a -= b;
    return a;
}
template <typename T, T MOD>
ModInt<T, MOD> operator*(ModInt<T, MOD> a, const ModInt<T, MOD> &b)
{
    a *= b;
    return a;
}
template <typename T, T MOD>
ModInt<T, MOD> operator/(ModInt<T, MOD> a, const ModInt<T, MOD> &b)
{
    a /= b;
    return a;
}
}
SegTree<Math::ModInt<int, 998244353>> dp;
int main()
{
    int n, k;
    io >> n >> k;
    vector<pair<int, int>> segs(k);
    io >> segs;
    dp.build(vector<Math::ModInt<int, 998244353>>(n));
    dp.update(0, 1);
    for (int j = 1; j < n; j++) {
        for (int i = 0; i < k; i++) {
            dp.update(j,
                dp.query(
                    max(0, j - segs[i].second), max(j - segs[i].first + 1, 0)));
        }
    }
    // for (int i = 0; i < n; i++) { io.WS(dp.query(i, i + 1).x); }
    io.WL(dp.query(n - 1, n).x);
    return 0;
}

Measured memory_bytes: 8224