#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define fi first
#define se second
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define MOD 1000000007
#define mod 998244353
#define pie 3.14159265358979323846264338327950L
#define N 200009
#define M 2000009
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define umap unordered_map<int, int>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
#define int long long
using namespace std;
 
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }

  vector<pair<int,int> > factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return vector<pair<int,int> >();
    vector<pair<int,int> > res(1, make_pair(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.push_back(make_pair(p, 1));
      }
    }
    return res;
  }
};



void test_case()
{
    int n,k;
    cin>>n>>k;

    set<int> st;
    vector<pii> arr;
    rep(j,k) {
      int l, r;
      cin>>l>>r;
      arr.pb(mpr(l,r));
      for(int i=l; i<=r; i++) {
        st.insert(i);
      }
    }

    int sum[n+1];

    int dp[n+1];
    memset(dp,0,sizeof(dp));
    memset(sum,0,sizeof(sum));

    sum[0] =0;
    sum[1] = 1;

    dp[1] = 1;

    for(int i=2; i<=n; i++) {
      int cnt = 0;
      for(int j=0; j<k; j++) {
        int l_temp, r_temp;
          if(arr[j].first >= i) {
            continue;
          } else {
             l_temp = min(arr[j].first, i-1);
             r_temp = min(arr[j].second, i-1);
          }
          int val = sum[i-l_temp] - sum[i-r_temp-1];;
          if(val < 0) {
            val = val + mod;
          }
          cnt+= val%mod;
          cnt = cnt % mod;
           // cout<<l_temp<<" "<<r_temp<<" ";
      }
      // cout<<i<<" "<<cnt<<endl<<endl;;
      dp[i] = cnt % mod;
      sum[i]= (sum[i-1] + cnt) % mod;
    }

    // for(int i=0; i<n; i++) {
    //    cout<<sum[i]<<" ";
    // }

    cout<<dp[n]<<endl;

    





}
 
signed main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(20);
 
    //  freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
 
    int t = 1;
    // cin >> t;
    while (t--)
    {
        test_case();
    }
}

Measured memory_bytes: 16060