#include <bits/stdc++.h>
using namespace std;
long long nxt() {
  long long x;
  cin >> x;
  return x;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n = nxt();
  long long k = nxt();
  set<long long> coins;
  for (int i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    while (x <= y) {
      coins.insert(x);
      x++;
    }
  }
  n--;
  vector<long long> dp(n + 1, 0);
  dp[0] = 1;
  for (long long x = 1; x <= n; x++) {
    for (long long c : coins) {
      if (x - c >= 0) {
        dp[x] =
            ((dp[x] % 998244353LL) + (dp[x - c] % 998244353LL)) % 998244353LL;
      } else
        break;
    }
  }
  cout << dp[n] << '\n';
  return 0;
}
