#include <bits/stdc++.h>
using namespace std;
long mod = 998244353;
set<int, greater<int> > s1;
void merge(int x, int y) {
  for (int i = x; i <= y; i++) s1.insert(i);
}
int main() {
  int n, k;
  cin >> n >> k;
  int x, y;
  for (int i = 0; i < k; i++) {
    cin >> x >> y;
    merge(x, y);
  }
  vector<int> v(s1.begin(), s1.end());
  vector<int> dp(n + 1, 0);
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j : v) {
      if (i > j) {
        dp[i] = (dp[i] + dp[i - j]) % mod;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}
