#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  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);
  }
  n--;
  vector<int> dp(n + 1, 0);
  dp[0] = 1;
  int m = 998244353;
  for (int x = 1; x <= n; ++x) {
    for (int c : s) {
      if (x - c >= 0) {
        dp[x] += dp[x - c];
        dp[x] %= m;
      }
    }
  }
  cout << dp[n];
  return 0;
}
