#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int main() {
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> v(k);
  for (int i = 0; i < k; ++i) {
    long long l, r;
    cin >> l >> r;
    v[i] = make_pair(l, r);
  }
  vector<long long> a(n + 1, 0);
  a[1] = 1;
  for (int i = 1; i < n; ++i) {
    for (auto p : v) {
      for (int j = i + p.first; j <= min(i + p.second, n); ++j) {
        a[j] += a[i];
        a[j] %= MOD;
      }
    }
  }
  cout << a[n] << endl;
}
