#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
long long dp[200005];
long long find(int at, int e, vector<int>& v) {
  if (at == e) return 1;
  if (at > e) return 0;
  if (dp[at] != -1) return dp[at];
  long long ans = 0;
  for (int i = 0; i < v.size(); i++) {
    long long curr = find(at + v[i], e, v);
    ans = (ans + curr) % mod;
  }
  dp[at] = ans % mod;
  return dp[at];
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i <= n; i++) {
    dp[i] = -1;
  }
  int k;
  cin >> k;
  int s[k], e[k];
  for (int i = 0; i < k; i++) {
    cin >> s[i] >> e[i];
  }
  vector<int> v;
  for (int i = 0; i < k; i++) {
    for (int j = s[i]; j <= e[i]; j++) {
      v.push_back(j);
    }
  }
  long long ans = find(1, n, v);
  cout << ans;
  return 0;
}
