#include <bits/stdc++.h>
using namespace std;
long long dp[200001];
int main() {
  long long n, k;
  cin >> n >> k;
  pair<long long, long long> r[k];
  for (long long i = 0; i < (long long)k; i++) {
    cin >> r[i].first >> r[i].second;
  }
  vector<long long> s;
  for (long long i = 0; i < (long long)k; i++)
    for (long long j = (long long)(r[i].first); j < (long long)r[i].second + 1;
         j++) {
      s.push_back(j);
    }
  for (long long i = 0; i < (long long)n; i++) dp[i] = 0;
  dp[0] = 1;
  for (long long i = 0; i < (long long)n; i++) {
    for (long long j = 0; j < (long long)s.size(); j++) {
      if (i + s[j] < n) {
        dp[i + s[j]] += dp[i];
        dp[i + s[j]] %= 998244353;
      }
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
