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