#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  set<int> s;
  while (k--) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++) s.insert(i);
  }
  vector<long long> dp(n + 1, 0);
  dp[0] = 1;
  for (int i = 1; i <= n; i++) {
    for (auto x : s) {
      if (i - x >= 0) dp[i] += dp[i - x];
    }
  }
  cout << dp[n - 1] % 998244353;
}
