#include <bits/stdc++.h>
using namespace std;
long long barr[200100], M = 998244353;
void solveTestCase() {
  long long n, i, j, k, l;
  cin >> n >> k;
  vector<pair<long long, long long> > arr(k + 1);
  for (i = 1; i <= k; i++) cin >> arr[i].first >> arr[i].second;
  barr[1] = 1;
  barr[2] = -1;
  for (i = 1; i <= n; i++) {
    barr[i] += barr[i - 1];
    barr[i] %= M;
    if (!barr[i]) continue;
    for (j = 1; j <= k; j++) {
      barr[i + arr[j].first] += barr[i];
      barr[i + arr[j].first] %= M;
      barr[i + arr[j].second + 1] += (M - barr[i]);
      barr[i + arr[j].second + 1] %= M;
    }
  }
  cout << barr[n] << '\n';
}
int main() {
  long long t, n, i, j, k, l, m;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long p;
  t = 1;
  for (long long T = 1; T <= t; T++) {
    solveTestCase();
  }
  return 0;
}
