#include <bits/stdc++.h>
using namespace std;
int n;
long long dp[300005];
bool check[200005];
long long mod = 998244353;
vector<int> arr;
long long f(int curr) {
  long long& ret = dp[curr];
  if (~ret) return ret;
  ret = 0;
  for (int i = 0; i < arr.size(); i++) {
    if (curr + arr[i] > n) break;
    ret += f(curr + arr[i]);
    ret %= mod;
  }
  return ret;
}
int main() {
  int k;
  cin >> n >> k;
  while (k--) {
    int a, b;
    cin >> a >> b;
    for (int i = a; i <= b; i++) check[i] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (check[i]) arr.push_back(i);
  }
  memset(dp, -1, sizeof(dp));
  dp[n] = 1;
  cout << f(1);
}
