#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  vector<int> A(n + 1, 0);
  for (int i = 0; i < k; i++) {
    int a;
    int b;
    cin >> a;
    cin >> b;
    for (int j = a; j <= b; j++) A[j] = 1;
  }
  vector<int> B;
  int hkl = A.size();
  for (int i = 0; i < hkl; i++) {
    if (A[i] == 1) B.push_back(i);
  }
  long long int dp[n + 1];
  dp[0] = 0;
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    long long int ans = 0;
    int ok = B.size();
    for (int j = 0; j < ok; j++) {
      if (i - B[j] > 0)
        ans += dp[i - B[j]];
      else
        break;
    }
    dp[i] = ans;
  }
  cout << dp[n] % 998244353 << endl;
}
