#include <bits/stdc++.h>
using namespace std;
const long long M = 1000000007;
const long long MM = 998244353;
const long long inf = INT_MAX;
long long begtime = clock();
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
template <typename T, typename F>
void chmax(T& a, F b) {
  if (b > a) a = b;
}
template <typename T, typename F>
void chmin(T& a, F b) {
  if (b < a) a = b;
}
long long mulmod(long long a, long long b, long long c) {
  long long ans = 0;
  long long y = a % c;
  while (b) {
    if (b & 1) {
      (ans += y) %= c;
    }
    y = y * 2 % c;
    b >>= 1;
  }
  return ans;
}
long long powM(long long a, long long b, long long m) {
  if (a <= 0) return 0;
  a %= m;
  long long ans = 1LL;
  while (b) {
    if (b & 1) ans = ans * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return ans;
}
long long powMbig(long long a, long long b, long long m) {
  if (a <= 0) return 0;
  a %= m;
  long long ans = 1LL;
  while (b) {
    if (b & 1) ans = mulmod(ans, a, m);
    a = mulmod(a, a, m);
    b >>= 1;
  }
  return ans;
}
long long poww(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a;
    a = a * a;
    b >>= 1;
  }
  return ans;
}
string tostring(long long x) {
  stringstream sss;
  sss << x;
  string ans = sss.str();
  return ans;
}
const long long N = 2e5 + 5;
long long n;
vector<long long> bit;
void update(long long x, long long delta) {
  while (x <= 2 * n) {
    (bit[x] += delta) %= MM;
    x += x & -x;
  }
}
long long sum(long long x) {
  long long ret = 0;
  while (x) {
    (ret += bit[x]) %= MM;
    x -= x & -x;
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n;
  bit.assign(2 * n + 1, 0);
  vector<long long> f(n + 1);
  f[1] = 1;
  long long k;
  cin >> k;
  vector<pair<long, long> > a(k);
  for (long long i = 0; i < k; i++) {
    cin >> a[i].first >> a[i].second;
  }
  for (long long i = 1; i < n; i++) {
    long long val = sum(i);
    if (i == 1) val = 1;
    for (long long j = 0; j < k; j++) {
      long long nl = i + a[j].first;
      long long nr = i + a[j].second;
      update(nl, val);
      update(nr + 1, -val);
    }
  }
  long long ans = sum(n);
  cout << ans % MM;
  return 0;
}
