#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
long long int dp[200005];
long long int cal(long long int n, vector<long long int>& v) {
  long long int sum = 0;
  for (auto i : v) {
    if (n - i <= 0) continue;
    if (dp[n - i] == -1) dp[n - i] = cal(n - i, v);
    sum = (sum + dp[n - i]) % mod;
  }
  return sum;
}
void solve() {
  long long int n, k;
  cin >> n >> k;
  vector<long long int> v;
  for (int i = 0; i < k; ++i) {
    long long int u, b;
    cin >> u >> b;
    for (long long int j = u; j <= b; j++) v.push_back(j);
  }
  memset(dp, -1, sizeof dp);
  dp[1] = 1;
  sort(v.begin(), v.end());
  long long int ans = cal(n, v);
  cout << ans << endl;
}
int main() {
  long long int t = 1;
  while (t--) {
    solve();
  }
}
