#include <bits/stdc++.h>
using namespace std;
using namespace std;
vector<long long int> dp(200001, -1);
long long int sums(vector<long long int> pos, long long int i,
                   long long int target) {
  long long int ans = 0;
  if (target <= 0 || i >= pos.size()) return 0;
  if (target == 1) return 1;
  if (dp[target] != -1) return dp[target];
  ans = sums(pos, i, target - pos[i]) + sums(pos, i + 1, target);
  ans = ans % 998244353;
  return dp[target] = ans;
}
int32_t main() {
  long long int n, k;
  cin >> n >> k;
  set<long long int> vals;
  long long int a, b;
  for (long long int i = 0; i < k; i++) {
    cin >> a >> b;
    for (long long int j = a; j <= b; j++) {
      vals.insert(j);
    }
  }
  vector<long long int> pos;
  for (auto i : vals) {
    pos.push_back(i);
  }
  long long int ans = sums(pos, 0, n);
  cout << dp[n];
}
