#include <bits/stdc++.h>
using namespace std;
long long N, M, K;
long long H, W;
long long X, Y, Z, C;
const int MAXN = 500005;
const long MOD = (long)(1e9 + 7);
const long long MODO = (long long)(998244353);
vector<long long> A;
vector<int> adj[MAXN];
long long perform(long long x) { return (x * (x + 1)) / 2LL; }
const int NAX = 1005;
long long dp[MAXN];
vector<long long> pos;
long long solve(long long N) {
  if (N < 0) return 0;
  if (!N) return 1;
  if (dp[N] != -1) return dp[N];
  long long ans = 0;
  for (int i = 0; i < pos.size(); ++i) {
    ans = (ans + solve(N - pos[i])) % MODO;
  }
  return dp[N] = ans % MODO;
}
int main() {
  cin >> N >> K;
  set<long long> Union;
  for (int i = 0; i < K; ++i) {
    int u, v;
    cin >> u >> v;
    for (int j = u; j <= v; ++j) Union.insert(j);
  }
  for (auto x : Union) pos.push_back(x);
  memset(dp, -1, sizeof(dp));
  cout << solve(N - 1) << "\n";
}
