#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, k;
int main() {
  scanf("%d %d", &n, &k);
  vector<pair<int, int>> s;
  for (int i = 0; i < k; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    s.push_back({l, r});
  }
  sort(s.begin(), s.end());
  vector<long long> cnt(n + 1, 0);
  cnt[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (auto it : s) {
      for (int k = it.first; k <= it.second; ++k) {
        if (i - k <= 0) {
          break;
        }
        cnt[i] += cnt[i - k];
      }
      cnt[i] %= mod;
    }
  }
  printf("%lld\n", cnt[n]);
  return 0;
}
