#include <bits/stdc++.h>
using namespace std;
vector<int> g[100004];
void ipgraph(int n, int m);
void dfs(int u, int par);
long long gcd(long long a, long long b);
unsigned long long factorial[1000004];
unsigned long long power(unsigned long long x, int y, int p) {
  unsigned long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
unsigned long long modInverse(unsigned long long n, int p) {
  return power(n, p - 2, p);
}
unsigned long long nc(unsigned long long n, int r, int p) {
  if (r == 0) return 1;
  return (factorial[n] * modInverse(factorial[r], p) % p *
          modInverse(factorial[n - r], p) % p) %
         p;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    int n, k;
    cin >> n >> k;
    vector<long long> a(n + 1, 0);
    vector<long long> p;
    int l, r;
    for (long long i = 0; i < k; i++) {
      cin >> l >> r;
      for (int i = l; i <= r; i++) {
        a[i] = 1;
        p.push_back(i);
      }
    }
    sort(p.begin(), p.end());
    for (int i = 1; i < n; i++) {
      if (a[i] != 0) {
        for (int u : p) {
          if (i + u > n) {
            break;
          } else {
            a[i + u] += (a[i] % 998244353);
            a[i + u] %= 998244353;
          }
        }
      }
    }
    cout << a[n - 1] << "\n";
  }
  return 0;
}
void dfs(int u, int par) {
  for (int v : g[u]) {
    if (v == par) continue;
    dfs(v, u);
  }
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
void ipgraph(int n, int m) {
  int i, u, v;
  while (m--) {
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
}
