#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 998244353;
const int MAX = 2e5 + 7;
long long int n, k, l, r;
vector<long long int> v;
long long int dp[MAX];
long long int solve(int idx) {
  if (idx == n) return 1LL;
  if (idx > n) return 0;
  if (dp[idx] != -1) return dp[idx];
  long long int ret = 0;
  for (int i = 0; i < v.size(); i++) {
    if (v[i] + idx > n) break;
    ret = ret % MOD + solve(idx + v[i]) % MOD;
    ret %= MOD;
  }
  return dp[idx] = ret % MOD;
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> n >> k;
  set<int> S;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    for (int j = l; j <= r; j++) S.insert(j);
  }
  for (int x : S) v.push_back(x);
  cout << solve(1) << endl;
  return 0;
}
