#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353, N = 2e5 + 100;
int n, k;
set<int> st;
int f[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  int l = 0, r = N;
  while (k--) {
    int x, y;
    cin >> x >> y;
    for (int i = x; i <= y; i++) {
      st.insert(i);
    }
  }
  f[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (auto j : st) {
      if (j >= i) break;
      f[i] = (f[i] + f[i - j]) % mod;
    }
  }
  cout << f[n] << endl;
}
