#include <bits/stdc++.h>
using namespace std;
int main() {
  long long mod = 998244353;
  long long n, k, a, b, c;
  vector<int> vec(0);
  cin >> n >> k;
  vector<int> sum(n + 1, 0);
  vector<pair<int, int>> pair;
  for (int i = 0; i < (int)(k); i++) {
    cin >> a >> b;
    pair.push_back(make_pair(a, b));
  }
  sort(pair.begin(), pair.end());
  sum[1] = 1;
  for (int i = 0; i < (int)(n + 1); i++) {
    if (i == 0 || i == 1) continue;
    sum[i] = sum[i - 1];
    for (int j = 0; j < (int)(k); j++) {
      c = 0;
      if (pair[j].first > i) break;
      if (pair[j].second > i) {
        sum[i] += sum[i - pair[j].first];
        sum[i] %= mod;
      } else {
        sum[i] += sum[i - (pair[j].first)] - sum[i - (pair[j].second + 1)];
        sum[i] %= mod;
      }
    }
  }
  c = sum[n] - sum[n - 1];
  while (c < 0) c += mod;
  cout << c;
}
