#include <bits/stdc++.h>
using namespace std;
long long cnt = 0;
long long timer = 0;
set<long long> s;
vector<pair<long long, long long> > vp;
long long factorial(long long n) {
  return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
bool sortByVal(const pair<double, double> &a, const pair<double, double> &b) {
  if (a.first == b.first) {
    return (a.second > b.second);
  } else
    return (a.first < b.first);
}
long long Powb(long long b, long long n) {
  if (n == 0) return 1LL;
  if (n == 1) return b;
  long long temp = Powb(b, n / 2);
  if (n % 2 == 0) {
    return (temp * temp) % 1000000007LL;
  } else {
    return (b * ((temp * temp) % 1000000007LL)) % 1000000007LL;
  }
}
long long countWays(vector<long long> &a, int m, int n, long long e) {
  vector<long long> count(n + 1, 0);
  count[0] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < m; j++)
      if (i >= a[j]) {
        count[i] += count[i - a[j]];
        count[i] %= e;
      }
  return count[n];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  while (t--) {
    long long k, n, i = 0, j = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0,
                    sum = 0, maxi = 0, to = 0;
    cin >> n >> k;
    vector<long long> a;
    for (i = 0; i < k; i++) {
      cin >> c >> d;
      for (j = c; j <= d; j++) {
        a.push_back(j);
      }
    }
    d = a.size();
    e = 998244353;
    c = countWays(a, d, n - 1, e);
    cout << c << "\n";
  }
}
