#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, k;
  cin >> n >> k;
  vector<pair<long long int, long long int> > v;
  for (long long int i = 0; i < k; i++) {
    long long int a, b;
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  set<long long int> s;
  for (int i = 0; i < k; i++) {
    for (int j = v[i].first; j <= v[i].second; j++) s.insert(j);
  }
  set<long long int>::iterator it;
  vector<long long int> a(n + 1, 0);
  a[0] = 0;
  a[1] = 1;
  for (long long int i = 2; i <= n; i++) {
    for (it = s.begin(); it != s.end(); it++) {
      if (i - (*it) > 0) {
        a[i] += a[i - (*it)];
      }
    }
  }
  cout << a[n] % 998244353 << "\n";
}
