#include <bits/stdc++.h>
using namespace std;
int n, k;
pair<int, int> g[11];
inline int read() {
  register int x = 0;
  register char ch = getchar();
  while (ch < '0' || ch > '9') {
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x;
}
int dp[400001];
int main() {
  n = read();
  k = read();
  register int i, j, p;
  for (i = 1; i <= k; ++i) {
    g[i].first = read();
    g[i].second = read();
  }
  dp[1] = 1;
  sort(g + 1, g + k + 1);
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= k && i + g[j].first <= n; ++j) {
      for (p = g[j].first; p <= g[j].second && i + p <= n; p++) {
        dp[i + p] = (dp[i + p] + dp[i]) % 998244353;
      }
    }
  }
  cout << dp[n];
}
