#include <bits/stdc++.h>
using namespace std;
set<long long> s;
long long p = 998244353;
long long dp[200001];
long long fun(long long n) {
  if (n == 1) return dp[n] = 1;
  if (n <= 0) return 0;
  if (dp[n] != -1) return dp[n];
  long long l = 0;
  for (auto it = s.begin(); it != s.end(); it++) {
    l = (l + fun(n - *it) % p) % p;
  }
  return dp[n] = l % p;
}
int32_t main() {
  long long t, n, i, j, k, l, r;
  cin >> n >> k;
  s.clear();
  memset(dp, -1, sizeof(dp));
  for (i = 1; i <= k; i++) {
    cin >> l >> r;
    for (j = l; j <= r; j++) s.insert(j);
  }
  cout << fun(n) % p;
}
