#include <bits/stdc++.h>
using namespace std;
int ROW[] = {+1, -1, +0, +0};
int COL[] = {+0, +0, +1, -1};
int X[] = {+0, +0, +1, -1, -1, +1, -1, +1};
int Y[] = {-1, +1, +0, +0, +1, +1, -1, -1};
int KX[] = {-2, -2, -1, -1, 1, 1, 2, 2};
int KY[] = {-1, 1, -2, 2, -2, 2, -1, 1};
int basePrime[] = {1009, 1013, 1019, 1021, 1031, 1223, 1229, 1231, 1237, 1249,
                   1289, 1291, 1297, 1301, 1303, 353,  359,  367,  373,  379,
                   859,  863,  877,  881,  883,  1931, 1933, 1949, 1951, 1973,
                   401,  409,  419,  421,  431,  1709, 1721, 1723, 1733, 1741,
                   3499, 3511, 3517, 3527, 3529, 929,  937,  941,  947,  953};
template <class XXX>
XXX GCD(XXX a, XXX b) {
  return b == 0 ? a : GCD(b, a % b);
}
template <class XXX>
XXX LCM(XXX a, XXX b) {
  return a * (b / GCD(a, b));
}
bool CMP(long long int a, long long int b) { return a > b; }
template <class XXX>
void fastread(XXX &number) {
  bool negative = false;
  register XXX c;
  number = 0;
  c = getchar();
  if (c == '-') {
    negative = true;
    c = getchar();
  }
  for (; (c > 47 && c < 58); c = getchar()) number = number * 10 + c - 48;
  if (negative) number *= -1;
}
template <class XXX>
inline XXX moduler(XXX num, XXX mod) {
  return (num >= mod ? num -= mod : num);
}
inline int Set(int pos, int N) { return N = N | (1 << pos); }
inline int Reset(int pos, int N) { return N = N & ~(1 << pos); }
inline bool Check(int pos, int N) { return (bool)(N & (1 << pos)); }
void OPFILE() {}
vector<int> a;
int n, k, dp[200007], mod = 998244353;
int sol(int sum) {
  if (sum == n) return 1;
  if (sum > n) return 0;
  int &ret = dp[sum];
  if (ret != -1) return ret;
  ret = 0;
  for (int i = 0; i < a.size(); i++) {
    ret = (ret % mod + sol(sum + a[i]) % mod) % mod;
  }
  return ret;
}
int main() {
  OPFILE();
  cin >> n >> k;
  set<int> st;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = a; j <= b; j++) st.insert(j);
  }
  a = vector<int>(st.begin(), st.end());
  for (int i = n - 1; i >= 1; i--) {
    for (int j = 0; j < a.size(); j++) {
      int x = i + a[j];
      if (x > n)
        break;
      else if (x == n)
        dp[i] += 1;
      else
        dp[i] += dp[i + a[j]];
      dp[i] %= mod;
    }
  }
  cout << dp[1] << endl;
  return 0;
}
