#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323846;
const int module = 1e9 + 7;
set<long long> s;
long long n, k, n1, n2;
int dp[2000001];
long long go(long long base) {
  for (auto it = s.begin(); it != s.end(); it++) {
    if (base + *(it) > n)
      continue;
    else if (base + *(it) == n)
      dp[base] += 1;
    else if (dp[base + *(it)])
      dp[base] += dp[base + *(it)], dp[base] %= 998244353;
    else
      dp[base] += go(base + *(it)), dp[base] %= 998244353;
  }
  return dp[base];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    cin >> n1 >> n2;
    for (int j = n1; j <= n2; j++) s.insert(j);
  }
  go(1);
  cout << dp[1] << endl;
  return 0;
}
