#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<pair<int, int>> d;
long dp[200005], sumdp[200005];
int dcnt = 0;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> k;
  d.reserve(k + 1);
  for (int i = 0; i < k; i++) {
    int s, e;
    cin >> s >> e;
    d.push_back({s, e});
  }
  dp[1] = 1;
  sumdp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (const auto& sect : d) {
      if (sect.first > i) continue;
      int ubound = i - sect.first;
      int lbound = min(i - sect.second, i);
      dp[i] =
          (dp[i] + 998244353 + sumdp[ubound] - sumdp[lbound - 1]) % 998244353;
    }
    sumdp[i] = (sumdp[i - 1] + dp[i]) % 998244353;
  }
  cout << dp[n] << '\n';
  return 0;
}
