#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
long long minthis(long long a, long long b) {
  if (a < b) {
    return a;
  }
  return b;
}
long long maxthis(long long a, long long b) {
  if (a > b) {
    return a;
  }
  return b;
}
int gcd(int a, int b) {
  if (a < 0) a = -a;
  if (b < 0) b = -b;
  while (b != 0) {
    a %= b;
    if (a == 0) return b;
    b %= a;
  }
  return a;
}
int findLargestDivisor(int n) {
  int max = 1;
  for (int i = 2; i < n; i++) {
    if (n % (i) == 0) {
      max = i;
    }
  }
  return max;
}
long long power(long long x, long long y) {
  long long temp;
  if (y == 0) return 1;
  temp = power(x, y / 2);
  if (y % 2 == 0)
    return temp * temp;
  else {
    if (y > 0)
      return x * temp * temp;
    else
      return (temp * temp) / x;
  }
}
vector<long long> v;
vector<long long> dp;
const long long mod = 998244353;
long long recurse(long long target, long long sum) {
  if (sum > target) return 0ll;
  if (sum == target) return 1ll;
  if (dp[sum] != -1) return dp[sum];
  long long ans = 0ll;
  for (long long i = 0; i < (long long)v.size(); i++) {
    ans += recurse(target, (sum + v[i]) % (mod));
    ans = ans % mod;
    dp[sum] = ans;
  }
  return ans;
}
void solve() {
  long long n, target;
  cin >> target >> n;
  target--;
  for (long long i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    for (int ii = x; ii <= y; ii++) {
      v.push_back(ii);
    }
  }
  dp.resize(target, -1);
  long long ans = recurse(target, 0);
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
