#include <bits/stdc++.h>
using namespace std;
bool prime[1000000 + 1];
vector<long long> v;
void sieve() {
  memset(prime, true, sizeof(prime));
  for (long p = 2; p * p <= 1000000; p++) {
    if (prime[p] == true) {
      for (long i = p * p; i <= 1000000; i += p) prime[i] = false;
    }
  }
  for (int i = 0; i <= 1000000; i++)
    if (prime[i]) v.push_back(i);
}
long long gcd(long long a, long long b) {
  if (a > b) swap(a, b);
  if (a == 0) return b;
  return gcd(b % a, a);
}
unsigned long long binpow(long long a, long long b) {
  if (b == 0) return 1;
  long long res = binpow(a, b / 2) % 1000000007;
  if (b % 2)
    return ((unsigned long long)res * (unsigned long long)res *
            (unsigned long long)a) %
           1000000007;
  else
    return ((unsigned long long)res * (unsigned long long)res) % 1000000007;
}
const int N = 2 * 1e5 + 5;
long long n, k;
long long m = 998244353;
vector<long long> st;
long long dp[N];
long long func(int index) {
  if (index == n) return 1;
  if (dp[index] != -1) return dp[index];
  dp[index] = 0;
  for (long long t : st) {
    if (index + t <= n) {
      dp[index] += func(index + t);
      dp[index] %= m;
    }
  }
  return dp[index] % m;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int T = 1;
  while (T--) {
    cin >> n >> k;
    for (int i = 0; i <= n; i++) dp[i] = -1;
    for (int i = 0; i < k; i++) {
      long long a, b;
      cin >> a >> b;
      for (long long j = a; j <= b; j++) st.push_back(j);
    }
    cout << func(1) % m;
  }
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
