#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 998244353;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> vpii;
  for (int i = 0; i < int(k); i++) {
    long long a, b;
    cin >> a >> b;
    vpii.push_back({a, b});
  }
  vector<long long> memo(n + 1);
  memo[1] = 1;
  map<int, int> start;
  map<int, int> stop;
  set<int> si;
  for (int i = 1; i < int(n + 1); i++) {
    for (auto x : start) {
      if (x.first == i) {
        si.insert(x.second);
        start.erase(x.first);
      }
    }
    for (auto x : si) {
      memo[i] += memo[x];
      memo[i] %= MOD;
    }
    for (int j = 0; j < int(k); j++) {
      start[i + vpii[j].first] = i;
      stop[i + vpii[j].second] = i;
    }
    for (auto x : stop) {
      if (x.first == i) {
        si.erase(x.second);
        stop.erase(x.first);
      }
    }
  }
  cout << memo[n] << endl;
}
