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