#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int main() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  vector<int> arr;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = a; j <= b; j++) {
      arr.push_back(j);
    }
  }
  sort(arr.begin(), arr.end());
  long long *dp = new long long[n + 1]();
  dp[1] = 1;
  dp[0] = 0;
  for (int i = 2; i <= n; i++) {
    int index = upper_bound(arr.begin(), arr.end(), i) - arr.begin();
    for (int j = 0; j < index; j++) {
      dp[i] = (dp[i] + dp[i - arr[j]]) % mod;
    }
  }
  cout << (dp[n] + mod) % mod << endl;
}
