#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int A[200005];
int f[200005];
int main() {
  int N, K;
  scanf("%d%d", &N, &K);
  set<int> s;
  set<int>::iterator it;
  int flag = 1;
  for (int i = 1; i <= K; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    for (int j = x; j <= y; ++j) s.insert(j);
  }
  f[1] = 1;
  for (int i = 1; i <= N; ++i) {
    for (it = s.begin(); it != s.end(); ++it) {
      if (i + *it <= N)
        f[i + *it] = (f[i + *it] + f[i]) % mod;
      else
        break;
    }
  }
  cout << f[N];
  return 0;
}
