/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first
ll MOD = 998244353;
vector<ll>adj[100005];
ll factor[1000005];

void icchhipadey()
{

  ll n, k;
  cin >> n >> k;
  set<ll>s;
  for (int i = 0; i < k; i++)
  {
    ll a, b;
    cin >> a >> b;
    for (int i = a; i <= b; i++)
    {
      s.insert(i);
    }
  }
  vector<ll>v;
  for (auto x : s)
  {
    v.pb(x);
  }
  ll dp[n + 1] = {0};
  dp[0] = 0;
  dp[1] = 1;
  for (ll i = 2; i <= n; i++)
  {
    for (ll j = 0; j < v.size(); j++)
    {
      if (i - v[j] >= 1)
      {
        dp[i] = (dp[i] % MOD + dp[i - v[j]] % MOD) % MOD;
      }
      else
      {
        break;
      }

    }

  }
  cout << dp[n] % MOD << endl;




}


int main()
{


  boost;
  icchhipadey();
}







