#include <bits/stdc++.h>
using namespace std;
long long dp[200001];
int main() {
  map<long long, long long> m;
  long long n, k;
  cin >> n >> k;
  for (int i = 0; i < (int)(k); i++) {
    long long l, r;
    cin >> l >> r;
    for (int j = (l); j < (int)(r + 1); j++) {
      m[j] = 1;
    }
  }
  vector<long long> v;
  for (int i = 0; i < (int)(n + 1); i++) {
    if (m[i] > 0) {
      v.push_back(i);
    }
  }
  dp[1] = 1;
  for (int i = (2); i < (int)(n + 1); i++) {
    for (auto diff : v) {
      if (i > diff) {
        dp[i] += dp[i - diff];
        dp[i] %= 998244353;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}
