#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int main() {
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> data(k);
  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    r -= l;
    data[i] = {l, r};
  }
  vector<long long> dp(2e5 + 20, 0);
  dp[1] = 1;
  for (long long i = 1; i < 2e5; i++) {
    if (dp[i] == 0) continue;
    for (long long j = 0; j < k; j++) {
      for (long long l = 0; l <= data[j].second; l++) {
        if (i + data[j].first + l >= 2e5 + 10) continue;
        dp[i + data[j].first + l] = (dp[i + data[j].first + l] + dp[i]) % MOD;
      }
    }
  }
  cout << dp[n] << endl;
}
