#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll mod = 998244353;
ll dp[200005];
vector<ll> vt;
int main() {
  ll n;
  cin >> n;
  dp[1] = 1;
  ll num;
  cin >> num;
  for (ll i = 0; i < num; ++i) {
    ll l, r;
    scanf("%lld %lld", &l, &r);
    for (ll j = l; j <= r; ++j) {
      vt.push_back(j);
    }
  }
  sort(vt.begin(), vt.end());
  for (ll i = 1; i < n; ++i) {
    for (ll j : vt) {
      if (i + j > n) {
        break;
      }
      dp[i + j] += dp[i];
      dp[i + j] %= mod;
    }
  }
  cout << dp[n] % mod << endl;
  return 0;
}
