#include <bits/stdc++.h>
using namespace std;
int64_t MOD = 998244353;
double PI = 3.141592653589793;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int64_t> dp(N);
  vector<int64_t> table;
  for (int i = 0; i < K; i++) {
    int L, R;
    cin >> L >> R;
    for (int j = L; j <= R; j++) table.push_back(j);
  }
  sort(table.begin(), table.end());
  dp[0] = 1;
  for (int i = 1; i < N; i++) {
    for (int j = 0; j < table.size(); j++) {
      int tmp = i - table[j];
      if (tmp < 0)
        break;
      else
        dp[i] = (dp[i] + dp[tmp]) % MOD;
    }
  }
  cout << dp[N - 1];
}
