#include <bits/stdc++.h>
using namespace std;
long long fastpow(long long a, long long b, long long m = 998244353LL) {
  long long res = 1;
  a %= m;
  while (b > 0) {
    if (b & 1) res = (res * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return res;
}
long long n;
const long long maxN = 1e5 + 5;
long long tree[maxN];
void update(long long index, long long val) {
  while (index <= n) {
    tree[index] = (tree[index] + val) % 998244353LL;
    index += (index & -index);
  }
}
long long read(long long index) {
  long long sum = 0;
  while (index) {
    sum = (sum + tree[index]) % 998244353LL;
    index -= (index & -index);
  }
  return sum;
}
long long getSum(long long low, long long high) {
  if (high <= 0) {
    return 0;
  }
  if (low <= 1) {
    return read(high);
  }
  return (read(high) - read(low - 1) + 998244353LL) % 998244353LL;
}
int32_t main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ;
  long long k, a, b;
  cin >> n >> k;
  vector<vector<long long>> s;
  while (k--) {
    cin >> a >> b;
    s.push_back({a, b});
  }
  update(1, 1);
  for (long long i = 2; i <= n; i++) {
    for (auto x : s) {
      update(i, getSum(i - x[1], i - x[0]));
    }
  }
  cout << (read(n) - read(n - 1) + 998244353LL) % 998244353LL << endl;
  return 0;
}
