#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const int MOD = 998244353;
int main(void) {
  long long n, k;
  cin >> n >> k;
  vector<long long> ans(n + 10, 0);
  vector<pair<long long, long long>> s(k);
  vector<long long> sum(n + 10, 0);
  for (int i = (0); i < (k); ++i) {
    cin >> s[i].first >> s[i].second;
  }
  ans[0] = 1, sum[1] = 1;
  for (int i = (1); i < (n); ++i) {
    for (auto it : s) {
      long long l = max((long long)0, i - it.second);
      long long r = max((long long)0, i - it.first + 1);
      ans[i] += sum[r] - sum[l];
      ans[i] %= MOD;
    }
    sum[i + 1] = ans[i] + sum[i];
    sum[i + 1] %= MOD;
  }
  cout << ans[n - 1] << endl;
  return 0;
}
