#include <bits/stdc++.h>
const unsigned long long mod = 998244353;
const int lim = 200000;
unsigned long long dp[lim + 2];
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> seg(k);
  for (int i = 0; i < k; i++) cin >> seg[i].first >> seg[i].second;
  sort(seg.begin(), seg.end());
  for (int i = 1; i <= n; i++) dp[i] = 0;
  dp[1] = 1;
  for (int i = 1 + seg[0].first; i <= n; i++) {
    bool exhaust = false;
    for (int j = 0; j < k; j++) {
      for (int l = seg[j].first; l <= seg[j].second; l++) {
        if (i - l < 1) {
          exhaust = true;
          break;
        }
        dp[i] = (dp[i] + dp[i - l]) % mod;
      }
      if (exhaust) break;
    }
  }
  cout << dp[n];
}
