#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100, mod = 998244353;
long long dp[maxn];
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int> > a(k);
  for (int i = 0; i < k; i++) cin >> a[i].first >> a[i].second;
  dp[0] = 0;
  dp[1] = 1;
  for (int i = 1; i <= n; i++)
    if (i > 1) {
      long long res = 0;
      for (int j = 0; j < k; j++) {
        int l = i - a[j].second - 1;
        int r = i - a[j].first;
        l = max(l, 0);
        r = max(r, 0);
        res += dp[r];
        res -= dp[l];
      }
      dp[i] = dp[i - 1] + res;
      dp[i] %= mod;
    }
  cout << dp[n] - dp[n - 1];
  return 0;
}
