#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

static long long INF = (1LL << 62);
const LL C = 998244353;

LL N, K;
LL dp[200004] = {0};
int main(int argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N >> K;
  vector<LL> D;
  for (int i = 0; i < K; i++) {
    LL l, r;
    cin >> l >> r;
    for (LL j = l; j <= r; j++) {
      D.push_back(j);
    }
  }
  sort(D.begin(), D.end());
  dp[1] = 1;
  if (D[0] == 1) {
    dp[2] = 1;
  } else {
    dp[2] = 0;
  }

  for (int i = 3; i <= N; i++) {
    for (int j = 0; j < D.size() && i - D[j] >= 1; j++) {
      dp[i] += dp[i - D[j]];
      dp[i] %= C;
    }
    dp[i] %= C;
  }
  printf("%lld\\n", dp[N]);
  return 0;
}

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

static long long INF = (1LL << 62);
const LL C = 998244353;

LL N, K;
// dp[i] はマスiに行ける個数(をCで割ったもの)
LL dp[200004] = {0};
LL sdp[200004] = {0}; // dpの累積和

int main(int argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N >> K;
  vector<int> L, R;
  for (int i = 0; i < K; i++) {
    int l, r;
    cin >> l >> r;
    L.push_back(l);
    R.push_back(r);
  }
  sort(L.begin(), L.end());
  sort(R.begin(), R.end());

  dp[0] = 0;
  dp[1] = 1;
  sdp[0] = 0;
  sdp[1] = 1;

  for (int i = 2; i <= N; i++) {
    for (int j = 0; j < K; j++) {
      LL l = max(0, i - R[j] - 1);
      LL r = max(0, i - L[j]);
      dp[i] += (sdp[r] - sdp[l]);
      dp[i] %= C;
      if (dp[i] < 0)
        dp[i] += C;
    }
    sdp[i] = sdp[i - 1] + dp[i];
    sdp[i] %= C;
  }
  printf("%lld\\n", dp[N]);
  return 0;
}