#include <bits/stdc++.h>
const long long MAX = 200009, MOD = 1000000007, BASE = 311, inf = 1e9;
int du[] = {1, 0}, dv[] = {0, 1};
struct node {
  long long v;
  long long d;
  long long e;
};
using namespace std;
long long f[MAX], n, k, a[MAX], m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    long long l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) a[++m] = j;
  }
  sort(a + 1, a + 1 + m);
  f[1] = 1;
  for (int s = 2; s <= n; s++)
    for (int i = 1; i <= m; i++) {
      if (a[i] <= s) f[s] = (f[s] + f[s - a[i]]) % 998244353;
    }
  cout << f[n];
  return 0;
}
