#include <bits/stdc++.h>
using namespace std;
const int Mod = 998244353, N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
long long f[N], a[20], b[20], c[20];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> a[i] >> b[i];
  }
  f[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (int j = 0; j < m; ++j) {
      c[j] += (i - a[j] >= 1 ? f[i - a[j]] : 0) -
              (i - b[j] - 1 >= 1 ? f[i - b[j] - 1] : 0);
      f[i] = (f[i] + c[j]) % Mod;
    }
  }
  cout << (f[n] + Mod) % Mod << endl;
  return 0;
}
