#include <bits/stdc++.h>
using namespace std;
long long countWays(long long n, long long *arr1, long long size) {
  long long count = 0;
  long long res[n + 1];
  res[0] = 1;
  res[1] = 1;
  for (long long i = 2; i <= n; i++) {
    count = 0;
    for (long long j = 0; j < size; j++) {
      if (i - j > 0 && arr1[j] != 0) {
        count = ((count % 998244353) + (res[i - j]) % 998244353) % 998244353;
      }
    }
    res[i] = count;
  }
  return res[n];
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k, a, b;
  cin >> n >> k;
  set<long long> set1;
  vector<pair<long long, long long>> arr;
  long long maxi = INT_MIN;
  for (long long i = 0; i < k; i++) {
    cin >> a >> b;
    arr.push_back(make_pair(a, b));
    maxi = max(maxi, a);
    maxi = max(maxi, b);
  }
  long long arr1[maxi + 2];
  memset(arr1, 0, sizeof(arr1));
  for (long long i = 0; i < arr.size(); i++) {
    arr1[(arr[i].first)] = arr1[(arr[i].first)] + 1;
    arr1[(arr[i].second) + 1] = arr1[(arr[i].second) + 1] - 1;
  }
  long long sum = 0;
  for (long long i = 0; i < maxi + 2; i++) {
    sum += arr1[i];
    arr1[i] = sum;
  }
  long long size = maxi + 2;
  cout << countWays(n, arr1, size) << endl;
  return 0;
}
