#include <bits/stdc++.h>
using namespace std;
const int N = 998244353;
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  int n, k;
  cin >> n >> k;
  set<int> s;
  long long dp[n + 1];
  vector<pair<int, int> > vp;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    vp.push_back(make_pair(l, r));
  }
  sort(vp.begin(), vp.end());
  dp[1] = 1;
  dp[0] = 0;
  long long predp[n + 1];
  predp[0] = 0;
  predp[1] = 1;
  for (int i = 2; i <= n; i++) {
    long long ans = 0;
    for (int j = 0; j < k; j++) {
      int start = vp[j].first;
      int end = vp[j].second;
      int s = i - end, e = i - start;
      if (e <= 0) break;
      if (s <= 0) {
        ans += predp[e];
        ans %= N;
        break;
      }
      ans += (predp[e] - predp[s] + dp[s]);
      ans %= N;
    }
    dp[i] = ans;
    predp[i] = predp[i - 1] + dp[i];
    predp[i] %= N;
  }
  cout << dp[n];
  return 0;
}
