#include <bits/stdc++.h>
using namespace std;
const long long int nax = 1e5 + 5;
const long long int M = 998244353;
void solve() {
  long long int n, k;
  cin >> n >> k;
  vector<long long int> a;
  for (long long int i = 0; i < k; i++) {
    long long int l, r;
    cin >> l >> r;
    for (long long int j = l; j <= r; j++) a.push_back(j);
  }
  sort(a.begin(), a.end());
  vector<long long int> dp(n, 0);
  dp[0] = 1;
  for (long long int i = 1; i < n; i++) {
    for (long long int j = 0; j < a.size(); j++)
      if (i - a[j] >= 0) dp[i] = (dp[i] + dp[i - a[j]]) % M;
  }
  cout << dp[n - 1];
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  while (t--) solve();
  return 0;
}
