#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long> > s(k);
  for (int(i) = 0; (i) < (k); (i)++) {
    cin >> s[i].first >> s[i].second;
  }
  vector<long long> dp(n + 2);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    dp[i] = (dp[i] + dp[i - 1]) % 998244353;
    for (int(j) = 0; (j) < (k); (j)++) {
      if (i - s[j].first >= 1) {
        if (i - s[j].second < 1) {
          dp[i] = (dp[i] + dp[i - s[j].first]) % 998244353;
        } else {
          dp[i] = (dp[i] + dp[i - s[j].first] - dp[i - s[j].second - 1]) %
                  998244353;
        }
      }
    }
  }
  if (dp[n] - dp[n - 1] < 0) {
    cout << dp[n] - dp[n - 1] + 998244353 << endl;
  } else {
    cout << dp[n] - dp[n - 1] << endl;
  }
  return 0;
}
