#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long n, k;
long long dp[200010];
vector<int> v;
int main() {
  cin >> n >> k;
  for (long long i = 0; i < (n + 1); i++) dp[i] = 1000000007;
  for (long long i = 0; i < (k); i++) {
    int a, b;
    cin >> a >> b;
    for (long long j = (a); j < (b + 1); j++) v.push_back(j);
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  dp[1] = 1;
  for (long long i = (2); i < (n + 1); i++) {
    long long now = 0;
    for (long long j = 0; j < (v.size()); j++) {
      if (v[j] >= i) break;
      now += dp[i - v[j]];
      now %= 998244353;
    }
    dp[i] = min(dp[i], now);
    if (i + v[0] >= n) break;
  }
  cout << dp[n];
  return 0;
}
