#include <bits/stdc++.h>
using namespace std;
const char en = '\n';
long long int dp[200005];
long long int call(int pos, vector<int> &steps, int n) {
  if (pos == n) return 1;
  if (dp[pos] != -1) return dp[pos];
  long long int ans = 0;
  for (int i = 0; i < steps.size(); i++) {
    if (pos + steps[i] > n) break;
    ans = ans + call(pos + steps[i], steps, n);
    if (ans >= 998244353) ans %= 998244353;
  }
  return dp[pos] = ans;
}
void solve() {
  int n, k;
  scanf("%d %d", &n, &k);
  memset(dp, -1, sizeof(dp));
  vector<int> steps;
  for (int i = 0; i < k; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    for (int j = l; j <= r; j++) steps.push_back(j);
  }
  sort(steps.begin(), steps.end());
  cout << call(1, steps, n) << en;
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
