#include <bits/stdc++.h>
using namespace std;
vector<int> S;
long long dp[200010];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < k; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    for (int i = l; i <= r; i++) S.push_back(i);
  }
  dp[n] = 1;
  for (int i = n - 1; i >= 1; i--)
    for (int k : S)
      if (i + k <= n) dp[i] = (dp[i] + dp[i + k]) % 998244353;
  cout << dp[1] << endl;
  return 0;
}
