#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  set<int> s;
  vector<pair<int, int>> d(k);
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    d[i].first = x;
    d[i].second = y;
    for (int i = x; i < y + 1; i++) s.insert(i);
  }
  vector<long long> dp(n + 2, 0);
  for (auto a : s) dp[a + 1]++;
  for (int i = 1; i < n + 1; i++) {
    for (auto a : s) {
      if (i - a >= 0) dp[i] += dp[i - a];
      dp[i] %= 998244353;
    }
  }
  cout << dp[n] << endl;
}
