#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, K;
  cin >> N >> K;
  vector<long long> pos;
  long long a, b;
  for (int loop = 0; loop < K; loop++) {
    cin >> a >> b;
    while (a <= b) {
      pos.push_back(a);
      a++;
    }
  }
  vector<long long> dp(N, 0);
  dp[0] = 1;
  for (int loop = 0; loop < N - 1; loop++) {
    for (int loop2 = 0; loop2 < pos.size(); loop2++) {
      if (loop + pos[loop2] < N) {
        dp[loop + pos[loop2]] = (dp[loop + pos[loop2]] + dp[loop]) % 998244353;
      }
    }
  }
  cout << dp[N - 1] << endl;
  return 0;
}
