#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[200010];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  vector<int> s;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      s.push_back(j);
    }
  }
  sort(s.begin(), s.end());
  dp[1] = 1;
  for (int i = 1; i < n; i++) {
    if (dp[i] == 0) continue;
    for (auto ss : s) {
      if (i + ss > n) break;
      ll num = dp[i] + dp[i + ss];
      dp[i + ss] = num % 998244353;
    }
  }
  cout << dp[n] << "\n";
  return 0;
}
