#include <bits/stdc++.h>
using namespace std;
set<long long> s;
long long d[200005], mod = 998244353;
int main() {
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= k; i++) {
    long long x, y;
    cin >> x >> y;
    for (int j = x; j <= y; j++) {
      s.insert(j);
    }
  }
  vector<long long> a;
  for (auto i : s) {
    a.push_back(i);
  }
  d[1] = 1;
  for (long long i = 2; i <= n; i++) {
    for (auto j : a) {
      if (i > j)
        d[i] += d[i - j], d[i] %= mod;
      else
        break;
    }
  }
  cout << d[n] % mod << endl;
}
