#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t = 1;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    set<long long> s;
    for (long long i = 0; i < k; i++) {
      long long a, b;
      cin >> a >> b;
      for (long long j = a; j <= b; j++) s.insert(j);
    }
    vector<long long> dp(n + 1, 0);
    dp[1] = 1;
    for (long long i = 2; i <= n; i++) {
      for (auto j = s.begin(); j != s.end(); j++) {
        if (*j >= i)
          break;
        else
          dp[i] += dp[i - *j];
        dp[i] = dp[i] % 998244353;
      }
    }
    cout << dp[n] << endl;
  }
  return 0;
}
