#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long INF = 1e18;
const long double PI = acos((long double)-1);
const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1};
const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1},
          d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};
string to_string(char c) { return string(1, c); }
string to_string(const char* s) { return (string)s; }
string to_string(string s) { return s; }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(vector<bool> v) {
  string res;
  for (int i = (0); i < ((int)(v).size()); ++i) res += char('0' + v[i]);
  return res;
}
template <size_t SZ>
string to_string(bitset<SZ> b) {
  string res;
  for (int i = (0); i < (SZ); ++i) res += char('0' + b[i]);
  return res;
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31 - __builtin_clz(x); }
const long long MOD = 998244353;
const int MX = 1e5 + 5;
int tree[1];
int sum(int k, int a = 0) {
  while (k >= 1) {
    a += tree[k];
    k -= k & -k;
  }
  return a;
}
void add(int k, int x) {
  while (k <= MX) {
    tree[k] += x;
    k += k & -k;
  }
}
int find(vector<int>& ds, int i) {
  return ds[i] < 0 ? i : ds[i] = find(ds, ds[i]);
}
void solve() {
  long long N, K;
  cin >> N >> K;
  vector<int> L(K);
  vector<int> R(K);
  for (int i = (0); i < (K); ++i) cin >> L[i] >> R[i];
  vector<long long> dp(N + 1, 0);
  dp[1] = 1;
  vector<long long> sum(N + 1, 0);
  sum[1] = 1;
  for (int i = 2; i <= N; ++i) {
    for (int j = 0; j < K; ++j) {
      if (i - L[j] >= 1) {
        int a = max(0, i - R[j] - 1);
        dp[i] += sum[i - L[j]] - sum[a];
      }
    }
    dp[i] = (dp[i] + MOD) % MOD;
    sum[i] = (sum[i - 1] + dp[i] + MOD) % MOD;
  }
  cout << dp[N] << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
