#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int> > section(k);
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    section[i] = make_pair(l, r);
  }
  vector<long long> dp(n + 1);
  dp[1] = 1;
  dp[2] = -1;
  for (int i = 1; i < n; i++) {
    if (i > 1) dp[i] += dp[i - 1];
    for (int j = 0; j < k; j++) {
      if (i + section[j].first <= n)
        dp[i + section[j].first] += dp[i] % 998244353;
      if (i + section[j].second + 1 <= n)
        dp[i + section[j].second + 1] -= dp[i] % 998244353;
    }
  }
  dp[n] += dp[n - 1] % 998244353;
  cout << dp[n] << endl;
  return 0;
}
