#include <bits/stdc++.h>
using namespace std;
long long dp[200005];
const long long mod = 998244353;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  set<int> s;
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    for (int j = x; j <= y; j++) {
      s.insert(j);
    }
  }
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    if (dp[i]) {
      for (set<int>::iterator its = s.begin(); its != s.end(); its++) {
        int k = *its;
        if (i + k > n) {
          break;
        }
        dp[i + k] += dp[i];
        dp[i + k] %= mod;
      }
    }
  }
  printf("%lld\n", dp[n]);
  return 0;
}
