#include <bits/stdc++.h>
using namespace std;
long long dp[200000 + 1];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    set<pair<long long, long long> > s;
    vector<long long> v;
    for (long long i = 0; i <= k - 1; i++) {
      long long p, q;
      cin >> p >> q;
      s.insert({p, q});
    }
    for (auto x : s) {
      long long y = x.first;
      while (y <= x.second) v.push_back(y++);
    }
    dp[0] = 0;
    dp[1] = 1;
    for (long long i = 2; i <= n; i++) {
      for (long long j = 0; j < v.size(); j++) {
        if (i - v[j] > 0) {
          dp[i] = (dp[i] + dp[i - v[j]]) % 998244353;
        }
      }
    }
    cout << dp[n] << endl;
  }
}
