#include <bits/stdc++.h>
const int m = 998244353;
using namespace std;
int main() {
  long long n, k, a, b;
  cin >> n >> k;
  set<long long> s;
  while (k--) {
    cin >> a >> b;
    for (int i = a; i <= b; i++) s.insert(i);
  }
  if (n == 1) {
    cout << 0;
    return 0;
  }
  vector<long long> r(n + 1);
  r[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int x : s) {
      if (i - x < 0) break;
      r[i] = (r[i] + r[i - x]) % m;
    }
  }
  cout << r[n];
}
