#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> L(k), R(k);
  vector<ll> sum(n + 1, 0), ans(n + 1, 0);
  ans[1] = sum[1] = 1;
  for (int i = 0; i < k; i++) {
    cin >> L[i] >> R[i];
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int l = max(0, i - L[j]), r = max(0, i - R[j] - 1);
      ans[i] += sum[l] - sum[r];
    }
    ans[i] += mod;
    ans[i] %= mod;
    sum[i] = (sum[i - 1] + ans[i]) % mod;
  }
  cout << ans[n] << endl;
}
