#include <bits/stdc++.h>
using namespace std;
int n, k;
int d[200005], dp[200005];
int dcnt = 0;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int s, e;
    cin >> s >> e;
    for (int j = s; j <= e; j++) {
      d[dcnt++] = j;
    }
  }
  sort(d, d + dcnt);
  dp[0] = 0;
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < dcnt && d[j] < i; j++) {
      dp[i] = (dp[i] + dp[i - d[j]]) % 998244353;
    }
  }
  cout << dp[n] << '\n';
  return 0;
}
