#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  short negative = 1;
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') negative = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  x *= negative;
}
long long quickpower(long long n, long long k) {
  long long ans = 1;
  while (k) {
    if (k % 2) {
      ans *= n;
      ans %= 998244353;
    }
    n *= n;
    n %= 998244353;
    k /= 2;
  }
  return ans;
}
string int_to_string(int n) {
  string s = "";
  while (n) {
    int now = n % 10;
    s += now + '0';
    n /= 10;
  }
  reverse(s.begin(), s.end());
  return s;
}
int string_to_int(string s) {
  int n = 0;
  for (int i = 0, _n = s.size(); i < s.size(); i++) {
    n *= 10;
    n += s[i] - '0';
  }
  return n;
}
int n;
int k;
vector<int> v;
long long dp[200100];
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 0, _n = k; i < k; i++) {
    int x, y;
    cin >> x >> y;
    for (int i = (x), _b = (y); i <= _b; i++) v.push_back(i);
  }
  sort(v.begin(), v.end());
  dp[0] = 1;
  for (int i = (1), _b = (n - 1); i <= _b; i++) {
    for (int j = 0, _n = v.size(); j < v.size(); j++) {
      if (v[j] > i) break;
      dp[i] = (dp[i] + dp[i - v[j]]) % 998244353;
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
