#include <bits/stdc++.h>
using namespace std;
long long ways[200005];
vector<pair<long long, long long> > seg;
int main() {
  long long n, k, i, j, x, y, cnt = 0;
  cin >> n >> k;
  seg.push_back(make_pair(0, 0));
  for (i = 1; i <= k; i++) {
    cin >> x >> y;
    seg.push_back(make_pair(x, y));
  }
  memset(ways, 0, sizeof(ways));
  sort(seg.begin(), seg.end());
  ways[1] = 1;
  for (i = 2; i <= n; i++) {
    for (j = 1; j <= k; j++) {
      y = i - seg[j].first;
      if (y >= 1) {
        x = max((long long)1, i - seg[j].second);
        ways[i] = (ways[i] + ways[y] - ways[x - 1] + 998244353) % 998244353;
      }
    }
    ways[i] = (ways[i] + ways[i - 1]) % 998244353;
  }
  cout << ways[n] - ways[n - 1] << endl;
}
