#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
long long int max(long long int a, long long int b) { return a > b ? a : b; }
long long int gcd(long long int a, long long int b) {
  if (a == 0) {
    return b;
  }
  return b == 0 ? a : gcd(b, a % b);
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << "[ " << *it << " = " << a << " ]";
  err(++it, args...);
}
const long long int inf = 9223372036854775800;
const int MAXN = 100001;
const int LOGN = 22;
const int MAXBIT = 62;
const long double PI = 3.141592653589793;
const int DIGITSIZE = 18;
long long int mod = 1e9 + 7;
long long int MOD = 998244353;
int x4[] = {1, -1, 0, 0};
int y4[] = {0, 0, 1, -1};
int x8[] = {1, 1, 1, -1, -1, -1, 0, 0};
int y8[] = {1, 0, -1, 1, 0, -1, 1, -1};
bool takeTestCases = 0;
bool printCaseNo = 0;
long long int bit[MAXN + 1];
void update(int pos, int val) {
  while (pos <= MAXN) {
    bit[pos] += val % MOD;
    bit[pos] %= MOD;
    pos += (pos & -pos);
  }
}
int query(int pos) {
  long long int ans = 0;
  while (pos > 0) {
    ans += bit[pos] % MOD;
    ans %= MOD;
    pos -= (pos & -pos);
  }
  return ans;
}
void getac(int T) {
  int n, k;
  cin >> n >> k;
  vector<pair<long long int, long long int> > q;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    q.push_back({l, r});
  }
  long long int dp[n + 1];
  for (int i = 0; i <= n; i++) {
    dp[i] = 0;
  }
  dp[0] = 0;
  dp[1] = 1;
  update(1, 1);
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int l = q[j].first;
      int r = q[j].second;
      l = max(i - l, 0);
      r = max(i - r - 1, 0);
      dp[i] += query(l);
      dp[i] -= query(r);
      dp[i] += MOD;
      dp[i] %= MOD;
    }
    update(i, dp[i]);
  }
  cout << dp[n] << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cerr.tie(NULL);
  ;
  int t = 1;
  if (takeTestCases) {
    cin >> t;
  }
  int t_t = 1;
  while (t--) {
    if (printCaseNo) (i) cout << "Case #" << i << ": ";
    (t_t);
    getac(t_t);
    t_t++;
  }
  cerr << "Total time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms"
       << '\n';
  return 0;
}
