#include <bits/stdc++.h>
using namespace std;

const int M = 998244353;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> lr(k);
  for (int i = 0; i < k; i++) {
    cin >> lr[i].first >> lr[i].second;
  }
  vector<int> dp(n + 1);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      dp[i] = (dp[i] + dp[max(i - lr[j].first, 0)] - dp[max(i - lr[j].second - 1, 0)]) % M;
      if (dp[i] < 0) {
        dp[i] += M;
      }
    }
    if (i != n) {
      dp[i] = (dp[i] + dp[i - 1]) % M;
    }
  }
  cout << dp[n] << '\n';
  return 0;
}