#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
long long int solveHelper(int n, map<int, bool>& myMap, int i,
                          long long int dp[]) {
  if (dp[i] != -1) {
    return dp[i];
  }
  long long int ans = 0;
  for (map<int, bool>::iterator u = myMap.begin(); u != myMap.end(); u++) {
    if (i + u->first <= n) {
      ans += solveHelper(n, myMap, i + u->first, dp);
      ans = ans % mod;
    } else {
      break;
    }
  }
  return ans;
}
long long int solve(int n, map<int, bool>& myMap) {
  long long int dp[n + 1];
  for (int i = 0; i < n + 1; i++) {
    dp[i] = -1;
  }
  dp[n] = 1;
  return solveHelper(n, myMap, 1, dp);
}
int main() {
  int n, k;
  cin >> n >> k;
  map<int, bool> myMap;
  long long int count = 0;
  bool is1 = false;
  for (int i = 0; i < k; i++) {
    int low, high;
    cin >> low >> high;
    if (low == 1) is1 = true;
    for (int j = low; j <= high; j++) {
      myMap[j] = true;
    }
  }
  if (!is1) {
    cout << 0 << endl;
    return 0;
  }
  cout << solve(n, myMap) << endl;
}
