#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  set<ll> s;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    while (l <= r) {
      s.insert(l);
      l++;
    }
  }
  vector<ll> ss;
  for (auto x : s) ss.push_back(x);
  sort(ss.begin(), ss.end());
  vector<ll> dp(n);
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    for (auto x : ss) {
      if (i - x >= 0) {
        dp[i] = (dp[i] + dp[i - x]) % MOD;
      } else
        break;
    }
  }
  cout << dp[n - 1] << endl;
}
