#include <bits/stdc++.h>
using namespace std;
long long solve(long long loc, vector<long long>& pattern,
                vector<long long> action) {
  long long cnt(0);
  if (loc == 1) {
    return 1;
  }
  if (pattern[loc] == -1) {
    for (int i = action.size() - 1; i >= 0; --i) {
      if (loc - action[i] > 0) {
        cnt += (solve(loc - action[i], pattern, action) % 998244353);
        cnt %= 998244353;
      }
    }
    pattern[loc] = cnt;
    return cnt;
  } else {
    return pattern[loc];
  }
}
int main(int argc, char const* argv[]) {
  long long N;
  long long K;
  long long cnt(0);
  cin >> N >> K;
  long long L[K];
  long long R[K];
  for (int i = 0; i < K; ++i) {
    cin >> L[i] >> R[i];
  }
  vector<long long> pattern_map(N, -1);
  vector<long long> fill_map(N + 1, -1);
  vector<long long> action_map;
  for (int i = 0; i < K; i++) {
    for (int j = L[i]; j <= R[i]; j++) {
      if (fill_map[j] == -1) {
        action_map.push_back(j);
        fill_map[j] = 0;
      }
    }
  }
  for (int i = action_map.size() - 1; i >= 0; --i) {
    if (N - action_map[i] > 0) {
      cnt += (solve(N - action_map[i], pattern_map, action_map) % 998244353);
      cnt %= 998244353;
    }
  }
  cout << cnt % 998244353 << endl;
  return 0;
}
