#include <bits/stdc++.h>
using namespace std;
int BIG = 998244353;
map<int, long long> cache = {};
set<int> st = {};
vector<int> v;
long long calc(int num) {
  long long result = 0;
  if (cache.count(num)) {
    return cache[num];
  }
  if (num < 0) {
    return 0;
  }
  if (num == 0) {
    return 1;
  }
  for (int a : v) {
    int target = num - a;
    if (target < 0) {
      break;
    }
    result += calc(num - a) % BIG;
  }
  cache[num] = result % BIG;
  return result % BIG;
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      st.insert(j);
    }
  }
  vector<int> vec(st.begin(), st.end());
  sort(vec.begin(), vec.end());
  v = vec;
  cout << calc(n - 1) << endl;
  return 0;
}
