#include <bits/stdc++.h>
constexpr auto mod = 1000000007;
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
bool prime(long long n) {
  long long cnt = 0;
  for (long long i = 1; i <= sqrt(n); i++) {
    if (n % 1 == 0) cnt++;
  }
  if (cnt != 1)
    return false;
  else
    return n != 1;
}
struct UnionFind {
  vector<long long> r;
  UnionFind(long long N) { r = vector<long long>(N, -1); }
  long long root(long long x) {
    if (r[x] < 0) return x;
    return r[x] = root(r[x]);
  }
  bool unite(long long x, long long y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (r[x] > r[y]) swap(x, y);
    r[x] += r[y];
    r[y] = x;
    return true;
  }
  long long size(long long x) { return -r[root(x)]; }
};
vector<long long> v;
long long n, m, cnt = 0, ans = 0, aa[220000];
pair<long long, long long> pp[220000];
string s, ss[220000];
queue<long long> que;
signed main() {
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    cin >> pp[i].first >> pp[i].second;
  }
  sort(pp, pp + m);
  aa[1] = 1;
  for (long long i = 0; i < n; i++) {
    if (aa[i + 1] == 0) {
      continue;
    }
    for (long long j = 0; j < m; j++) {
      for (long long k = pp[j].first; k < min(pp[j].second + 1, n - i); k++) {
        aa[i + 1 + k] += aa[i + 1];
        aa[i + 1 + k] %= 998244353;
      }
    }
  }
  cout << aa[n];
}
