#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int INF = 1e9 + 7;
constexpr ll INFL = 9 * 1e18;
constexpr int dx[4] = {1, 0, -1, 0};
constexpr int dy[4] = {0, 1, 0, -1};
int inline digit(ll num) {
  int tmp = 0;
  while (num) {
    tmp++;
    num /= 10;
  }
  return tmp;
}
template <typename T>
inline T SUM(vector<T> vec) {
  return accumulate((vec).begin(), (vec).end(), (T)0);
}
template <typename T>
inline T digitSum(T num) {
  T sum = 0;
  while (num) {
    sum += num % 10;
    num /= 10;
  }
  return sum;
}
template <typename T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename T>
inline T lcm(T a, T b) {
  T g = gcd(a, b);
  return a / g * b;
}
template <typename T>
inline T power(T a, T b) {
  T tmp = 1;
  for (int i = 0; (i) < ((int)(b)); ++(i)) {
    tmp *= a;
  }
  return tmp;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
inline void print(T&& x) {
  cout << setprecision(32) << x << endl;
}
int main() {
  ll waru = 998244353;
  int n, k;
  cin >> n >> k;
  vector<int> s(n + 1, 0);
  vector<ll> dp(n + 1, 0);
  vector<pair<int, int>> lr(k);
  for (int i = 0; (i) < ((int)(k)); ++(i)) {
    int l, r;
    cin >> l >> r;
    r++;
    lr[i] = (make_pair(l, r));
    for (int j = l; j <= r; ++j) {
      s[j] = 1;
    }
  }
  dp[1] = 1;
  vector<int> kA(k, 0);
  for (int i = 2; i <= n; ++i) {
    for (int j = 0; (j) < ((int)(k)); ++(j)) {
      if (i - lr[j].second > 0) {
        kA[j] -= dp[i - lr[j].second];
        kA[j] %= waru;
        if (kA[j] < 0) kA[j] += waru;
      }
      if (i - lr[j].first > 0) {
        kA[j] += dp[i - lr[j].first];
        kA[j] %= waru;
      }
      dp[i] += kA[j];
      dp[i] %= waru;
    }
  }
  print(dp[n]);
  return 0;
}
