#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long i, j;
    long long mod = 998244353;
    vector<long long> coins;
    for (i = 0; i < k; i++) {
      long long x, y;
      cin >> x >> y;
      if (x == y)
        coins.push_back(x);
      else {
        for (j = x; j < y + 1; j++) coins.push_back(j);
      }
    }
    sort(coins.begin(), coins.end());
    vector<long long> dp(n, 0);
    dp[0] = 1;
    for (i = 1; i < n; i++) {
      for (long long coin : coins) {
        if (coin <= i) {
          long long ramt = i - coin;
          dp[i] = ((dp[i] % mod) + (dp[ramt] % mod)) % mod;
        }
      }
    }
    cout << dp[n - 1];
  }
  return 0;
}
