#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<pair<int, int> > seg;
  for (int i = (0); i < (K); ++i) {
    int L, R;
    cin >> L >> R;
    seg.push_back(pair<int, int>(L, R));
  }
  long long cur = 0;
  long long a[300000];
  for (int i = (0); i < (N + 1); ++i) a[i] = 0;
  a[0] = 1;
  a[1] = -1;
  for (int i = (0); i < (N); ++i) {
    cur = (cur + a[i]) % 998244353;
    for (int j = (0); j < (seg.size()); ++j) {
      a[i + seg[j].first] = (a[i + seg[j].first] + cur) % 998244353;
      a[i + seg[j].second + 1] = (a[i + seg[j].second + 1] - cur) % 998244353;
    }
  }
  cout << (cur + 998244353) % 998244353 << endl;
}
