#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  set<int> nums;
  while (k--) {
    int x, y;
    cin >> x >> y;
    for (int i = x; i <= y; i++) nums.insert(i);
  }
  vector<int> dp(n + 1);
  dp[0] = 1;
  auto it = nums.begin();
  int num = *(it);
  for (int i = num; i <= n; i++) {
    for (int j : nums) {
      if (i < j) break;
      dp[i] = (dp[i] % 998244353 + dp[i - j] % 998244353) % 998244353;
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
