#include <bits/stdc++.h>
using namespace std;
long long int grid(long long int *dp, long long int i, long long int n,
                   vector<long long int> v) {
  if (i > n) return 0;
  if (i == n) return 1;
  if (dp[i] != -1) return dp[i] % 998244353;
  long long int sum = 0;
  for (long long int j = 0; j < v.size(); j++) {
    sum = (sum % 998244353 + grid(dp, i + v[j], n, v) % 998244353 + 998244353) %
          998244353;
  }
  return dp[i] = sum % 998244353;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    set<long long int> second;
    while (k--) {
      long long int x, y;
      cin >> x >> y;
      for (long long i = x; i <= y; i++) second.insert(i);
    }
    vector<long long int> v;
    set<long long int>::iterator it;
    for (it = second.begin(); it != second.end(); ++it) v.push_back(*it);
    long long int dp[n + 1];
    for (int i = 0; i <= n; i++) dp[i] = -1;
    cout << grid(dp, 1, n, v);
  }
}
