#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  vector<int> a;
  while (k--) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; ++i) {
      a.push_back(i);
    }
  }
  sort(a.begin(), a.end());
  long long dp[n];
  memset(dp, 0, sizeof(dp));
  dp[0] = 1;
  for (int sum = 1; sum <= n - 1; ++sum) {
    for (auto x : a) {
      if (sum - x < 0) continue;
      dp[sum] = dp[sum] + dp[sum - x];
      dp[sum] = dp[sum] % 998244353;
    }
  }
  cout << dp[n - 1];
}
