#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
long long MOD = 1e9 + 7;
long long MOD1 = 1e9 + 123;
long long MOD2 = 1e9 + 321;
long long MOD3 = 998244353;
long long W[200002];
vector<pair<int, int>> v;
int fun(int n) {
  if (W[n] != -1) return W[n];
  int c = 0, a, b;
  for (auto h : v) {
    a = h.first, b = h.second;
    if (n < a) break;
    for (; a <= b; a++)
      if (n < a)
        break;
      else
        c = (c + fun(n - a)) % MOD3;
  }
  W[n] = c;
  return W[n];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t, c, p, a, n, q, k, i, l, m, u, f, j, x, y, b, d;
  cin >> n;
  cin >> k;
  memset(W, -1, sizeof(W));
  W[0] = 0;
  W[1] = 1;
  for (i = 0; i < k; i++) cin >> a >> b, v.push_back({a, b});
  sort(v.begin(), v.end());
  cout << fun(n);
  return 0;
}
