#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  long long k;
  cin >> k;
  long long diff[20005];
  memset(diff, 0, sizeof diff);
  vector<pair<long long, long long> > v;
  for (long long i = 0; i < k; i++) {
    long long x;
    cin >> x;
    long long y;
    cin >> y;
    v.push_back({x, y});
  }
  diff[0] = 0;
  diff[1] = 1;
  long long last = 0;
  for (long long i = 1; i <= n + 5; i++) {
    if (i > 2) {
      diff[i] += diff[i - 1];
    }
    long long cur = diff[i] % 998244353;
    for (long long j = 0; j < v.size(); j++) {
      diff[i + v[j].first] += cur;
      diff[i + v[j].second + 1] -= cur;
    }
  }
  cout << diff[n] % 998244353 << '\n';
  return 0;
}
