#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> S;
  for (int i = 0; i < K; ++i) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; ++j) {
      S.push_back(j);
    }
  }
  vector<int> dp(N + 1);
  dp[1] = 1;
  for (int i = 2; i <= N; ++i) {
    int count = 0;
    for (int s : S) {
      if (i > s) {
        count = (count + dp[i - s]) % 998244353;
      }
    }
    dp[i] += (count % 998244353);
  }
  cout << dp[N] << endl;
  return 0;
}
