#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int main() {
  long long n, k;
  cin >> n >> k;
  long long s[k][2];
  for (int i = 0; i < k; i++) {
    cin >> s[i][0] >> s[i][1];
  }
  vector<long long> p(n + 1, 0);
  p[1] = 1;
  for (long long i = 2; i <= n; i++) {
    p[i] += p[i - 1];
    for (long long j = 0; j < k; j++) {
      long long x = s[j][0], y = s[j][1];
      if (i - x >= 1) p[i] += p[i - x] - p[i - min(y, i - 1) - 1];
      p[i] %= mod;
    }
    p[i] %= mod;
  }
  cout << (p[n] - p[n - 1] + mod) % mod;
  return 0;
}
