#include <bits/stdc++.h>
using namespace std;
int n, k;
void solve() {
  cin >> n >> k;
  unordered_set<int> jumps;
  while (k--) {
    int x, y;
    cin >> x >> y;
    for (int i = x; i <= y; i++) jumps.insert(i);
  }
  long long int dp[n + 1];
  memset(dp, 0, sizeof(dp));
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (auto j : jumps) {
      if (j < i) dp[i] = (dp[i] + dp[i - j]) % 998244353;
    }
  }
  cout << dp[n];
}
int main() {
  {
    ios_base ::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  };
  int t = 1;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
