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