#include <bits/stdc++.h>
#define LOWBIT(x) (x&(-x))
#define MOD(x) (((x)%Mod+Mod)%Mod)
#define sp putchar(' ')
#define en putchar('\n')
const int MAXN = 1000005 ;
using namespace std ;
using VI = vector<int64_t> ;
int64_t n, m, T, u, v, a, b ,phi, Mod = 998244353;

int64_t powEx(int64_t base ,int64_t n, int64_t Mod) {
    int64_t ret = 1 ;
    while(n) {
        if(n & 1) {
            ret = ret * base % Mod ;
        }
        base = base * base % Mod ;
        n >>= 1 ;
    }
    return ret % Mod ;
}

int64_t euler(int64_t n)
{
       int64_t ret(n),x(n);
       for(int64_t i(2);i*i<=x;i++){
           if(x%i==0){
               ret=ret/i*(i-1);
               while(x%i==0) x/=i;
           }
       }
      if(x>1) ret=ret/x*(x-1);
      return ret;
}

int64_t f(int64_t a,int64_t i) {
    if (__gcd(a, m) == 1) {
        return powEx(a, powEx(2, i, phi), m) ;
    } else {
        if (pow(2.0, i) < phi) {
            return powEx(a, 1LL << i, m) ;
        } else {
            return powEx(a, powEx(2, i, phi) + phi, m) ;
        }
    }
}

int64_t solve(int64_t x, int64_t n)
{
    if(n == 1) return (x*x)%m ;
    int64_t mid = n >> 1 ;
    return (solve(x, mid) + solve(f(x, mid) , n - mid)) ;
}
class BIT
{
static const int MAXN = 1000005 ;
public:
    /**树状数组区间更新+区间查询*/
    /**设c[i] = a[i] - a[i-1]*/
    /**a[1]+...+a[n]=(n+1)(c[1]+...+c[n])- (1*c[1]+2*c[2]+...+n(c[n])) */
    int64_t sum1[MAXN];///差分数组:(c[1]+...+c[n])
    int64_t sum2[MAXN];///(1*c[1]+2*c[2]+...+n(c[n]))
    void clear(int n) {for(int i(0);i<=n;++i) sum1[i] = sum2[i] = 0 ;}
    inline void range_add(int l, int r,int64_t val=1) ///区间修改
        {if(l>r)return ;add(l,val);add(r+1,-val);}
    inline int64_t range_Q(int l, int r) ///查询区间[l,r]的和
        {if(l>r)return 0 ;return Q(r) - Q(l - 1);}
private:
    inline void add(int pos, int64_t val=1) {///单点更新[单点修改用区间修改代替,这个函数不能用!!!!!!!]
        for (int i(pos);i<=MAXN;i+=LOWBIT(i)) {
            sum1[i] += val;
            sum1[i] %= Mod ;
            sum2[i] += val*(pos-1LL) ;
            sum2[i] %= Mod ;
        }

    }
    inline int64_t Q(int pos) {///查询[1,pos]前缀和
        int64_t ans(0);
        for (int i(pos);i>=1;i-=LOWBIT(i)) {
            ans += MOD(pos * sum1[i] - sum2[i]);
            ans = MOD(ans) ;
        }
        return ans;
    }
}bit;

int L[20],R[20] ;

int main()
{

    ios::sync_with_stdio(false) ;
//    while(cin >> n >> a >> m) {
//        phi = euler(m) ;
//        cout << f(a, n) << endl;
//    }
    while(cin >> n >> m) {
       bit.clear(n + 5) ;
       for(int i = 1;i <= m; ++ i) {
            cin >> L[i] >> R[i] ;
       }
       bit.range_add(1,1) ;
       for(int i = 1;i <= n; ++ i) {
//            cout << "i == "<< i << endl;
            for(int j = 1;j <= m; ++j) {
                int l = i - R[j], r = i - L[j] ;
                l = max(1, l) ;
//                cout <<"\t l == " << l <<", r == "<< r << endl ;
                if(r < 1) continue ;
                int64_t sum = bit.range_Q(l,r) ;
//                cout << "\tsum["<<l<<","<<r<<"] == " << sum << endl ;
                bit.range_add(i,i,sum) ;
            }
       }
       cout << bit.range_Q(n,n) << endl ;
    }
}
