#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353, N = 2e5 + 100;
int n, k;
int f[N], L[N], R[N], s[N];
void upd(int& x, int y) { x = (x + y) % mod; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> L[i] >> R[i];
  }
  f[1] = 1, s[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      if (i - L[j] < 1) continue;
      f[i] = (f[i] + (s[i - L[j]] - s[max(1, i - R[j]) - 1] + mod) % mod) % mod;
      s[i] = (s[i - 1] + f[i]) % mod;
    }
  }
  cout << f[n] << endl;
}
