#include <bits/stdc++.h>
using namespace std;
using vl = vector<long long>;
using vs = vector<string>;
using vc = vector<char>;
using ll = long long;
using vvl = vector<vector<ll> >;
using vvc = vector<vector<char> >;
using vd = vector<double>;
bool is_prime(int x) {
  if (x <= 1) return false;
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0) return false;
  return true;
}
ll p = 0, q = 0, y = 0;
int main() {
  ll n, k;
  cin >> n >> k;
  vl l(k), r(k), a(n), b(n + 1);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
    for (int j = l[i]; j <= r[i]; j++) {
      a[p] = j;
      p++;
    }
    sort(a.begin(), a.end());
    int value_to_remove = 0;
    a.erase(remove(a.begin(), a.end(), value_to_remove), a.end());
  }
  b[1] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < i + 1; j++) {
      for (int x = 0; x < p + 1; x++)
        if (a[x] == j) {
          q = 1;
          break;
        } else
          q = 0;
      if (q == 1) {
        b[i] += b[i - j];
        y += b[i - j];
        y %= 998244353;
      }
    }
  }
  cout << y << endl;
}
