#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5000;
const int mod = 998244353;
int n, m, T, a[N], vis[N], f[N], c[N];
vector<pair<int, int>> v;
int lowbit(int x) { return x & -x; }
void add(int x, int y) {
  for (int i = x; i < N; i += lowbit(i)) {
    c[i] = (c[i] + y) % mod;
  }
}
int sum(int x) {
  int tot = 0;
  for (int i = x; i; i -= lowbit(i)) {
    tot = (tot + c[i]) % mod;
  }
  return tot;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int l, r, i = 1; i <= m; i++) {
    cin >> l >> r;
    v.push_back(make_pair(l, r));
  }
  f[1] = 1;
  add(1, 1);
  for (int i = 2; i <= n; i++) {
    for (auto &j : v) {
      int l = i - j.second, r = i - j.first;
      if (l <= 0) {
        l = 1;
      }
      if (r <= 0) {
        continue;
      }
      f[i] = (sum(r) - sum(l - 1) + f[i]) % mod;
    }
    add(i, f[i]);
  }
  cout << f[n] << endl;
}
