#include <bits/stdc++.h>
using namespace std;
void jabru() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  set<int> s;
  for (long long i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      s.insert(j);
    }
  }
  vector<long long> dp(n + 1, 0);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (auto x : s) {
      if (i - x >= 1) {
        dp[i] += dp[i - x];
        dp[i] %= 998244353;
      }
    }
  }
  cout << dp[n] << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  t = 1;
  while (t--) jabru();
  return 0;
}
