#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> dp(n + 1);
  dp[0] = 0;
  dp[1] = 1;
  set<int> steps;
  for (int i = 0; i < m; i++) {
    int l, m;
    cin >> l >> m;
    for (int j = l; j <= m; j++) {
      steps.insert(j);
    }
  }
  for (int i = 2; i <= n; i++) {
    dp[i] = 0;
    for (auto it : steps) {
      if ((i - it) > 0 && dp[i - it] > 0) {
        dp[i] = (dp[i] + dp[i - it]) % mod;
      }
    }
  }
  cout << dp[n];
  return 0;
}
