#include <bits/stdc++.h>
using namespace std;
long long int countWays(vector<long long int> arr, long long int N,
                        long long int q = 998244353) {
  long long int m = arr.size();
  long long int count[N + 1];
  memset(count, 0, sizeof(count));
  count[0] = 1;
  for (long long int i = 1; i <= N; i++)
    for (long long int j = 0; arr[j] <= i; j++) {
      count[i] = (count[i] + count[i - arr[j]]) % q;
    }
  return count[N];
}
int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  int t;
  t = 1;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    set<long long int> s;
    while (k--) {
      long long int a, b;
      cin >> a >> b;
      for (long long int i = a; i <= b; i++) {
        s.insert(i);
      }
    }
    vector<long long int> v;
    for (auto i : s) {
      v.push_back(i);
    }
    cout << countWays(v, n - 1);
  }
  return 0;
}
