#include <bits/stdc++.h>
using namespace std;
int main() {
  const int mod = 998244353;
  int n, k;
  cin >> n >> k;
  vector<pair<long long int, long long int>> vp;
  vector<long long int> change(n, 0);
  change[0] = 1;
  for (int i = 0; i < k; i++) {
    long long int a, b;
    cin >> a >> b;
    vp.emplace_back(a, b);
  }
  long long int c = 0;
  for (int i = 0; i < n - 1; i++) {
    c += change[i];
    c %= mod;
    c += mod;
    c %= mod;
    for (auto p : vp) {
      int l = i + p.first, r = i + p.second + 1;
      if (l < n) {
        change[l] += c;
        change[l] %= mod;
        if (r < n) {
          change[r] -= c;
          change[r] %= mod;
        }
      }
    }
  }
  cout << change.back() << endl;
}
