#include <bits/stdc++.h>
using namespace std;
void sample() {}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t, n, m, k, x, y, w, i, j, count = 1, sum = 0, ans,
                                           mod = 998244353;
  cin >> n >> k;
  set<long long int> s;
  for (i = 0; i < k; i++) {
    cin >> x >> y;
    for (j = x; j <= y; j++) {
      s.insert(j);
    }
  }
  long long int dp[n + 1];
  for (i = 0; i <= n; i++) {
    dp[i] = 0;
  }
  dp[0] = 0;
  dp[1] = 1;
  for (i = 2; i <= n; i++) {
    auto it = s.upper_bound(i);
    if (it == s.begin()) {
      continue;
    }
    it--;
    while (it != s.begin()) {
      dp[i] += (dp[i - *it]) % mod;
      it--;
    }
    dp[i] += (dp[i - *it]) % mod;
  }
  cout << dp[n] % mod << endl;
}
