#include <bits/stdc++.h>
using namespace std;
const char en = '\n';
long long int dp[200005];
void solve() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<pair<int, int> > v;
  for (int i = 0; i < k; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    v.push_back(make_pair(l, r));
  }
  sort(v.begin(), v.end());
  dp[1] = 1;
  vector<long long int> sum(200005, 0);
  sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    long long int cnt = 0;
    for (int j = 0; j < k; j++) {
      long long int temp = sum[i - v[j].first];
      temp = (temp - sum[i - v[j].second - 1] + 998244353) % 998244353;
      cnt = (cnt + temp) % 998244353;
    }
    dp[i] = cnt;
    sum[i] = (dp[i] + sum[i - 1]) % 998244353;
  }
  cout << dp[n] << en;
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
