#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
vector<int> vis;
vector<vector<int>> adj;
vector<long double> dis;
long long int val;
long long int paths;
const int MAX = 1000001;
int factor[MAX] = {0};
vector<long long int> soln;
int getAns(int n, vector<pair<int, int>> &step) {
  if (n <= 0) return 0;
  if (n == 1) return soln[n] = 1;
  if (soln[n] >= 0) return soln[n];
  soln[n] = 0;
  for (int i = 0; i < step.size(); i++) {
    for (int j = step[i].first; j <= step[i].second; j++) {
      if (j >= n) {
        i = step.size();
        break;
      }
      soln[n] += getAns(n - j, step);
      soln[n] %= mod;
    }
  }
  return soln[n];
}
void solve() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> step;
  for (int i = 0; i < k; i++) {
    int u, v;
    cin >> u >> v;
    step.push_back({u, v});
  }
  sort(step.begin(), step.end());
  soln = vector<long long int>(n + 1, -1);
  cout << getAns(n, step) << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  t = 1;
  while (t--) solve();
}
