#include <bits/stdc++.h>
using namespace std;
long long int dp[200005];
long long int mod(long long int x) {
  return ((x) % 998244353 + 998244353) % 998244353;
}
int main() {
  long long int n, k;
  cin >> n >> k;
  set<long long int> s1;
  while (k--) {
    long long int a, b;
    cin >> a >> b;
    for (long long int i = a; i <= b; i++) {
      s1.insert(i);
    }
  }
  set<long long int>::iterator itr;
  vector<long long int> vec;
  memset(dp, 0, sizeof(dp));
  for (itr = s1.begin(); itr != s1.end(); ++itr) {
    vec.push_back(*itr);
    dp[*itr + 1] = 1;
  }
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 0; j < vec.size(); j++) {
      if (i - vec[j] > 0) {
        dp[i] = mod(mod(dp[i]) + mod(dp[i - vec[j]]));
      } else
        continue;
    }
  }
  cout << dp[n] << endl;
  return 0;
}
