#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const int MOD = 998244353;
long long dp[200005];
vector<int> opt;
long long solve(int n) {
  if (dp[n] != -1) return dp[n];
  if (n == 0)
    return dp[n] = 1;
  else {
    long long ret = 0;
    for (auto el : opt) {
      if (el <= n) {
        ret = (ret + solve(n - el)) % MOD;
      }
    }
    return dp[n] = ret;
  }
}
int main() {
  for (int i = 0; i < (int)(200005); i++) dp[i] = -1;
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < (int)(k); i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) opt.push_back(j);
  }
  cout << solve(n - 1) << endl;
  return 0;
}
