#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(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 x = l; x <= r; x++) s.push_back(x);
  }
  sort(s.begin(), s.end());
  vector<long long> dp(n + 1);
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (auto x : s) {
      if (i - x < 0) break;
      dp[i] = (dp[i] + dp[i - x]) % 998244353;
    }
  }
  cout << dp[n] << endl;
  return 0;
}
