#include <bits/stdc++.h>
using namespace std;
int have[200001];
int dp[200001];
set<int> s;
void solve() {
  int n;
  cin >> n;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    for (int i = a; i <= b; i++) have[i] = 1, s.insert(i);
  }
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    int ans = 0;
    for (auto it : s) {
      if (it >= i)
        goto end;
      else
        ans = (ans + dp[i - it]) % 998244353;
    }
  end:
    dp[i] = ans;
  }
  cout << dp[n] % 998244353 << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  while (t--) solve();
  return 0;
}
