#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int mod = 998244353;
template <class T>
inline bool Read(T& ret) {
  char c;
  int sgn;
  if (static_cast<void>(c = getchar()), c == EOF) return 0;
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (static_cast<void>(c = getchar()), c >= '0' && c <= '9')
    ret = ret * 10 + (c - '0');
  ret *= sgn;
  return 1;
}
template <class T>
inline void Write(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) Write(x / 10);
  putchar(x % 10 + '0');
}
int dp[N * 2] = {0};
void slove(int question_num) {
  int n, k;
  cin >> n >> k;
  unordered_map<int, int> num;
  for (int i = 1; i <= k; ++i) {
    int a, b;
    cin >> a >> b;
    num[a] = b;
  }
  dp[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (auto j : num) {
      for (int k = j.first; k <= j.second; ++k) {
        int cur = i - k;
        if (cur <= 0) break;
        dp[i] = (dp[i] + dp[cur]) % mod;
      }
    }
  }
  cout << (dp[n] % mod) << endl;
}
int main() {
  int num = 1;
  for (int i = 1; i <= num; ++i) {
    slove(i);
  }
  return 0;
}
