#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
template <class A, class B>
inline bool chmax(A &a, const B &b) {
  return b > a && (a = b, true);
}
template <class A, class B>
inline bool chmin(A &a, const B &b) {
  return b < a && (a = b, true);
}
template <class A>
inline long long abs(A &a) {
  return (a < 0 ? -a : a);
}
bool inLine(int x, int y, int mx, int my) {
  return (x >= 0 && y >= 0 && x < mx && y < my);
}
const long long inf = (1LL << 62);
const int MOD = (1e9) + 7;
const int mod = 998244353;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
signed main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < k; i++) cin >> l[i] >> r[i];
  vector<long long> ans(n + 10, 0);
  ans[0] = 0;
  long long sum = 1;
  for (int i = 1; i < n; i++) {
    sum += ans[i];
    sum %= mod;
    ans[i] = sum;
    for (int j = 0; j < k; j++) {
      if (i + l[j] <= n) ans[i + l[j]] += ans[i], ans[i + l[j]] %= mod;
      if (i + r[j] + 1 <= n)
        ans[i + r[j] + 1] -= ans[i], ans[i + r[j] + 1] %= mod;
    }
  }
  cout << ans[n] << '\n';
  return (0);
}
