#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
long long solve(long long n, long long k, vector<long long> l,
                vector<long long> r) {
  vector<long long> dp(n, 0);
  vector<long long> cand;
  for (int i = 0; i < k; i++) {
    for (long long j = l[i]; j <= r[i]; j++) {
      cand.push_back(j);
    }
  }
  dp[0] = 1;
  for (long long i = 0; i < n; i++) {
    if (dp[i] == 0) {
      continue;
    }
    for (auto c : cand) {
      if (i + c < n) {
        dp[i + c] += dp[i] % MOD;
      }
    }
  }
  return dp[n - 1];
}
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> l(k);
  vector<long long> r(k);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  cout << solve(n, k, l, r);
}
