#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long INF = 1001001001;
const long long LINF = 1001001001001001001;
void prvec(vector<long long> vec) {
  long long n = vec.size();
  for (int i = 0; i < (int)(n); i++) cout << i << " " << vec.at(i) << "\n";
}
void pr2d(vector<vector<long long>> vvec) {
  long long h = vvec.size();
  long long w = vvec.at(0).size();
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) {
      cout << vvec.at(i).at(j) << " ";
    }
    cout << "\n";
  }
}
long long n, k;
vector<long long> rui;
long long f(long long x) {
  if (x < 0) return 0;
  return rui[x];
}
int main() {
  cin >> n >> k;
  vector<pair<long long, long long>> a(0);
  for (int i = 0; i < (int)(k); i++) {
    long long l, r;
    cin >> l >> r;
    a.emplace_back(make_pair(l, r));
  }
  rui.resize(n, 0);
  rui[0] = 1;
  for (int i = 1; i < n; i++) {
    long long x = 0;
    for (int j = 0; j < (int)(k); j++) {
      x = (x + f(i - a.at(j).first) - f(i - a.at(j).second - 1)) % mod;
    }
    rui[i] = (rui[i - 1] + x) % mod;
  }
  cout << rui[n - 1] - rui[n - 2] << endl;
  return 0;
}
