#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
vector<long long> m;
long long dp[220000];
long long rec(long long n) {
  if (dp[n] > 0) return dp[n];
  if (n == 0) return 1;
  long long ret = 0;
  for (auto step : m) {
    if (n - step < 0) continue;
    ret = (ret + rec(n - step)) % mod;
  }
  return dp[n] = ret;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long n, k;
  cin >> n >> k;
  for (int i = 0; i < (k); ++i) {
    long long l, r;
    cin >> l >> r;
    for (long long j = l; j <= r; ++j) m.push_back(j);
  }
  cout << rec(n - 1) << endl;
  return 0;
}
