#include <bits/stdc++.h>
using namespace std;
const long long maxint = 2e18;
const long long minint = -2e18;
const int mod = 998244353;
int n;
const int M = 2e5 + 5;
long long done[M];
vector<pair<int, int>> edges;
long long solve(int position) {
  if (position > n) return 0;
  if (position == n) return 1;
  if (done[position] != -1) return done[position];
  long long res = 0;
  for (auto i : edges) {
    if (i.first + position > n) break;
    for (int start = i.first; start <= i.second; start++) {
      if (start + position > n) break;
      res += solve(position + start) % mod;
      res %= mod;
    }
    if (i.second + position > n) break;
  }
  return done[position] = res % mod;
}
int main() {
  memset(done, -1, sizeof(done));
  int k;
  scanf("%d%d", &n, &k);
  edges.assign(k, pair<int, int>());
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &edges[i].first, &edges[i].second);
  }
  sort(edges.begin(), edges.end());
  cout << solve(1) % mod << '\n';
  return 0;
}
