#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  long n, k;
  cin >> n >> k;
  vector<pll> data(k);
  for (int i = 0; i < (int)(k); i++)
    cin >> data.at(i).first >> data.at(i).second;
  vector<long> dp(200010, 0);
  vector<long> imos(200010, 0);
  dp.at(1) = 1;
  long acm = 0;
  for (int v = 1; v < n; v++) {
    if (v == 1) {
      for (int i = 0; i < (int)(k); i++) {
        imos.at(v + data.at(i).first) += 1;
        imos.at(v + data.at(i).second + 1) -= 1;
      }
    } else {
      acm += imos.at(v);
      acm %= 998244353;
      dp.at(v) = acm;
      for (int i = 0; i < (int)(k); i++) {
        imos.at(v + data.at(i).first) += acm;
        imos.at(v + data.at(i).first) % 998244353;
        imos.at(v + data.at(i).second + 1) -= acm;
        imos.at(v + data.at(i).second + 1) += 998244353;
        imos.at(v + data.at(i).second + 1) %= 998244353;
      }
    }
  }
  cout << (acm + imos.at(n)) % 998244353 << endl;
}
