#include <bits/stdc++.h>
using namespace std;
const long long inf = long long(1e18) + 1;
const long long mod = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k);
  vector<int> r(k);
  vector<int> s(n);
  int count = 0;
  vector<int> dp(n + 1);
  dp[1] = 1;
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  sort(l.begin(), l.end());
  sort(r.begin(), r.end());
  for (int i = 0; i < k; i++) {
    for (int j = l[i]; j <= r[i]; j++) {
      s[count] = j;
      count++;
    }
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < count; j++) {
      if (s[j] >= i) {
        break;
      }
      dp[i] += dp[i - s[j]];
      dp[i] %= mod;
    }
  }
  cout << dp[n] << endl;
  return 0;
}
