#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int n, k, l, r;
vector<pair<int, int> > seg;
long long dp[200001];
long long calc(int x) {
  if (x > n) return 0;
  if (x == n) return 1;
  if (dp[x] != -1) return dp[x];
  long long ans = 0;
  for (auto& s : seg) {
    for (int i = s.first; i <= s.second; i++) {
      ans = (ans + calc(x + i)) % MOD;
    }
  }
  return dp[x] = ans % MOD;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie();
  cin.exceptions(cin.failbit);
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> l >> r;
    seg.push_back({l, r});
  }
  for (int i = 1; i <= n; i++) dp[i] = -1;
  cout << calc(1);
}
