#include <bits/stdc++.h>
using namespace std;
template <class T, class C>
T max(T a, C b) {
  return ((a) > (T)(b) ? (a) : (T)(b));
}
template <class T, class C>
T min(T a, C b) {
  return ((a) < (T)(b) ? (a) : (T)(b));
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}, dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int upint(const void *a, const void *b) {
  return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0;
}
int downint(const void *a, const void *b) {
  return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0;
}
int upchar(const void *left, const void *right) {
  return strcmp((char *)left, (char *)right);
}
int downchar(const void *left, const void *right) {
  return strcmp((char *)right, (char *)left);
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) {
      res *= a;
      if (mod >= 1) res %= mod;
    }
    a *= a;
    if (mod >= 1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize() {}
const int MAX_N = 500010;
int bit[MAX_N + 1] = {0}, n;
long long sum(int i) {
  long long s = 0;
  while (i > 0) {
    s += bit[i];
    i -= i & (-i);
  }
  return s;
}
void add(int i, long long x) {
  while (i <= n) {
    bit[i] += x;
    i += i & (-i);
  }
}
long long rangesum(int l, int r) {
  if (l > r) return 0;
  return sum(r) - sum(l - 1);
}
int main(void) {
  initialize();
  long long m, i, j, k, result = 0;
  long long l[200010] = {0}, r[200010] = {0};
  long long dp[200010] = {0};
  string s;
  cin >> n >> k;
  for ((i) = 0; (i) < (k); (i)++) {
    cin >> l[i] >> r[i];
  }
  dp[1] = 1;
  for (i = 1; i <= n; i++) {
    dp[i] += dp[i - 1];
    for ((j) = 0; (j) < (k); (j)++) {
      if (i + l[j] <= n) {
        dp[i + l[j]] += dp[i];
        dp[i + l[j]] %= 998244353;
        if (i + r[j] <= n) dp[i + r[j] + 1] -= dp[i];
        if (dp[i + r[j] + 1] < 0) dp[i + r[j] + 1] += 998244353;
      }
    }
  }
  result = dp[n] - dp[n - 1];
  cout << result << endl;
  return 0;
}
