#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int max_size = 2e5 + 11;
int n, k, a, b;
map<int, int> m;
long long dp[max_size] = {};
int main() {
  scanf("%d%d", &n, &k);
  while (k--) {
    scanf("%d%d", &a, &b);
    for (int i = a; i <= b; ++i) m[i]++;
  }
  dp[1] = 1;
  for (int i = 1; i <= n; ++i) {
    for (auto& it : m) {
      if (i + it.first > n) continue;
      dp[i + it.first] += dp[i];
      dp[i + it.first] %= mod;
    }
  }
  printf("%lld", dp[n] % mod);
  return 0;
}
