#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long max(long long a, long long b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}
long long min(long long a, long long b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}
long long power(long long b, long long e) {
  if (e == 0) return 1;
  if (e % 2)
    return ((b * power((b) * (b), (e - 1) / 2)));
  else
    return power((b) * (b), e / 2);
}
long long modpower(long long b, long long e, long long q) {
  long long MOD = q;
  if (e == 0) return 1;
  if (e % 2)
    return ((b % MOD) * modpower((b % MOD) * (b % MOD), (e - 1) / 2, q)) % MOD;
  else
    return modpower((b % MOD) * (b % MOD), e / 2, q) % MOD;
}
void dpv(vector<long long> v) {
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << '\n';
}
void dpv(vector<pair<long long, long long> > v) {
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i].first << " " << v[i].second << '\n';
  }
}
void dpv(set<long long> v) {
  for (auto i : v) {
    cout << i << " ";
  }
  cout << '\n';
}
vector<long long> pref(100001, 0);
vector<long long> dp(100001, 0);
long long sum(long long l, long long r) {
  l = max(l, 0);
  return (pref[r] - (l == 0 ? 0 : pref[l - 1]));
}
void oblivious() {
  long long m1 = 998244353;
  long long n, k;
  cin >> n >> k;
  long long l[k], r[k];
  pref[1] = 1;
  dp[1] = 1;
  for (long long i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  for (long long i = 2; i <= n; i++) {
    for (long long j = 0; j < k; j++) {
      if (i - l[j] >= 0) {
        long long cur = sum(i - r[j], i - l[j]) % m1;
        dp[i] += cur % m1;
        dp[i] %= m1;
      }
    }
    pref[i] = (pref[i - 1] % m1 + dp[i] % m1) % m1;
  }
  dp[n] %= m1;
  cout << (dp[n] + m1) % m1 << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    oblivious();
  }
  return 0;
}
