#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int mod = 998244353;
int calcA(vector<int> s, vector<int> a, int n) {
  int res = 0;
  for (int i = 0; i < (s.size()); ++i) {
    if (n - s[i] >= 0) {
      res += a[n - s[i]];
      res %= mod;
    }
  }
  return res;
}
int main(void) {
  int n, k;
  cin >> n >> k;
  vector<int> s;
  for (int i = 0; i < (k); ++i) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++) {
      s.push_back(i);
    }
  }
  sort(s.begin(), s.end());
  vector<int> a(n, 0);
  a[0] = 1;
  for (int i = 1; i < n; i++) {
    a[i] = calcA(s, a, i);
  }
  cout << a[n - 1] << endl;
  return 0;
}
