#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
vector<int> dp;
vector<int> jumps;
int helper(int curr, int n) {
  if (curr == n) {
    return dp[curr] = 1;
  }
  if (dp[curr] != -1) return dp[curr];
  int sz = jumps.size();
  long long ans = 0;
  for (int i = 0; i < sz; i++) {
    if (curr + jumps[i] > n) break;
    ans = (ans + helper(curr + jumps[i], n)) % mod;
  }
  return dp[curr] = ans;
}
int main() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  jumps.clear();
  dp.clear();
  dp.assign(n + 1, -1);
  while (k--) {
    int a, b;
    cin >> a >> b;
    for (int i = a; i <= b; i++) {
      jumps.push_back(i);
    }
  }
  sort(jumps.begin(), jumps.end());
  cout << helper(1, n) << endl;
}
