#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 4;
long long ans[MAXN];
long long sum[MAXN];
const int MAXK = 10 + 4;
pair<int, int> seg[MAXK];
const int MO = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> seg[i].first >> seg[i].second;
  }
  ans[1] = 1;
  sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      int l = seg[j].first;
      int r = seg[j].second;
      ans[i] = (ans[i] + sum[max(0, i - l)] - sum[max(0, i - r - 1)]) % MO;
    }
    sum[i] = (sum[i - 1] + ans[i]) % MO;
  }
  cout << ans[n] << "\n";
  return 0;
}
