#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
int main() {
  long long n, k;
  cin >> n >> k;
  vector<bool> s(200010, false);
  for (int i = 0; i < (k); i++) {
    int sta, end;
    cin >> sta >> end;
    for (int j = sta; j <= end; j++) {
      s.at(j) = true;
    }
  }
  vector<long long> dp(200010);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      if (s.at(j)) dp[i] += dp[i - j];
      dp[i] %= mod;
    }
  }
  cout << dp[n] << endl;
}
