#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> a;
  map<int, int> mp;
  for (int i = 0; i < k; ++i) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; ++j) {
      a.push_back(j);
      ++mp[j];
    }
  }
  sort(a.begin(), a.end());
  vector<int> dp(n + 1, 0);
  dp[0] = 1;
  int sum = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < (int)a.size(); ++j) {
      if (a[j] > i) break;
      dp[i] = (dp[i] + dp[i - a[j]]) % MOD;
    }
  }
  cout << dp[n - 1] << '\n';
  return 0;
}
