#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
struct Data {
  int L, R;
};
int main() {
  int N, K;
  cin >> N >> K;
  Data data[K];
  for (int i = 0; i < K; ++i) {
    cin >> data[i].L >> data[i].R;
  }
  long long dp[N + 1];
  for (int i = 0; i < N + 1; ++i) {
    dp[i] = 0;
  }
  dp[1] = 1;
  for (int i = 2; i < N + 1; ++i) {
    for (int j = 0; j < K; ++j) {
      if (data[j].L <= i) {
        int num;
        num = dp[i - data[j].L] - dp[max(0, i - data[j].R - 1)];
        dp[i] = (dp[i] + num) % mod;
      }
    }
    dp[i] = (dp[i] + dp[i - 1]) % mod;
  }
  cout << dp[N] - dp[N - 1] << endl;
}
