#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll mod = 998244353;
  ll n, k;
  cin >> n >> k;
  vi v(k);
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    while (l <= r) v.push_back(l++);
  }
  sort(v.begin(), v.end());
  vector<ll> dp(n + 1, 0);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    dp[i] = 0;
    for (auto &e : v) {
      if (i - e < 1) break;
      dp[i] = (dp[i] + dp[i - e]) % mod;
    }
  }
  cout << dp[n];
}
