#include <bits/stdc++.h>
using namespace std;
long long int func(int n, vector<int>& jump, long long int dp[]) {
  if (dp[n] != -1)
    return dp[n];
  else {
    dp[n] = 0;
    for (auto j : jump) {
      if (n - j >= 1) {
        long long int output = func(n - j, jump, dp);
        dp[n] += output % 998244353;
      }
      if (n - j < 1) break;
    }
    dp[n] %= 998244353;
    return dp[n];
  }
}
int main() {
  int n, k;
  cin >> n >> k;
  int l[k], r[k];
  for (int i = 0; i < k; i++) cin >> l[i] >> r[i];
  vector<int> jump;
  for (int i = 0; i < k; i++) {
    for (int j = l[i]; j <= r[i]; j++) {
      jump.push_back(j);
    }
  }
  sort(jump.begin(), jump.end());
  long long int dp[n + 1];
  for (int i = 0; i <= n; i++) dp[i] = -1;
  dp[1] = 1;
  cout << func(n, jump, dp);
  return 0;
}
