#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 998244353;
vector<int> S(200100, 0);
vector<ll> mtd(200100, 0);
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> L(K), R(K);
  int x = 0;
  for (int i = 0; i < (int)(K); i++) {
    cin >> L.at(i) >> R.at(i);
    for (int j = L.at(i); j <= R.at(i); j++) {
      S.at(x) = j;
      x++;
    }
  }
  mtd.at(1) = 1;
  for (int i = 1; i < N; i++) {
    int y = 0;
    for (auto itr = S.begin(); itr != S.begin() + x;) {
      int ni = i + *itr;
      if (ni > N) {
        S.erase(itr);
        y++;
        continue;
      }
      mtd.at(ni) = (mtd.at(ni) + mtd.at(i)) % MOD;
      itr++;
    }
    x -= y;
  }
  cout << mtd.at(N);
  return 0;
}
