#include <bits/stdc++.h>
using namespace std;
char is_prime[100010];
int prime[100000];
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> left(k);
  vector<int> right(k);
  vector<long long> summin(k, 0);
  for (int i = 0; i < k; i++) {
    cin >> left[i] >> right[i];
  }
  vector<long long> sumlist(n + 1, 0);
  sumlist[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      if (i - left[j] >= 0) {
        summin[j] += sumlist[i - left[j]];
      }
      if (i - right[j] - 1 >= 0) {
        summin[j] -= sumlist[i - right[j] - 1];
      }
    }
    for (int j = 0; j < k; j++) {
      sumlist[i] += summin[j];
    }
    cerr << "i=" << i << " " << sumlist[i] << endl;
  }
  cout << (sumlist[n] % 998244353) << endl;
  return 0;
}
