#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long n, k, f[200001];
vector<long long> v;
signed main() {
  scanf("%lld %lld", &n, &k);
  for (long long i = 1; i <= k; i++) {
    long long l, r;
    scanf("%lld %lld", &l, &r);
    for (long long j = l; j <= r; j++) v.push_back(j);
  }
  f[1] = 1;
  for (long long i = 1; i <= n; i++)
    for (long long l = 0; l < v.size(); l++)
      if (i >= v[l]) f[i] = (f[i] + f[i - v[l]]) % mod;
  cout << f[n];
  return 0;
}
