#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long fact_table = 3200008;
long double Pi = 3.1415926535897932384626;
priority_queue<long long> pql;
priority_queue<pair<long long, long long>> pqp;
priority_queue<pair<long long, long long>> bag;
priority_queue<long long, vector<long long>, greater<long long>> pqls;
priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
               greater<pair<long long, long long>>>
    pqps;
long long dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
long long dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
const long long mod = 998244353ll;
long long mypow(long long a, long long b, long long m = mod) {
  long long x = 1;
  while (b) {
    while (!(b & 1)) {
      (a *= a) %= m;
      b >>= 1;
    }
    (x *= a) %= m;
    b--;
  }
  return x;
}
vector<long long> readvec(long long read) {
  vector<long long> res(read);
  for (int i = 0; i < read; i++) {
    cin >> res[i];
  }
  return res;
}
void YES(bool cond) {
  if (cond) {
    cout << "YES"
         << "\n";
    ;
  } else {
    cout << "NO"
         << "\n";
    ;
  }
  return;
}
void Yes(bool cond) {
  if (cond) {
    cout << "Yes"
         << "\n";
    ;
  } else {
    cout << "No"
         << "\n";
    ;
  }
  return;
}
void line() {
  cout << "--------------------"
       << "\n";
  ;
  return;
}
struct Timer {
  int64_t start;
  const int64_t CYCLES_PER_SEC = 2800000000;
  Timer() { reset(); }
  void reset() { start = getCycle(); }
  inline double get() { return (double)(getCycle() - start) / CYCLES_PER_SEC; }
  inline int64_t getCycle() {
    uint32_t low, high;
    __asm__ volatile("rdtsc" : "=a"(low), "=d"(high));
    return ((int64_t)low) | ((int64_t)high << 32);
  }
};
bool multicase = false;
void solve() {
  long long n, k, a, b;
  cin >> n >> k;
  vector<pair<long long, long long>> segments;
  for (int i = 0; i < k; i++) {
    cin >> a >> b;
    segments.push_back(pair<long long, long long>(a, b));
  }
  vector<long long> dp(n + 1), dpsum(n + 1);
  dp[1] = 1, dpsum[1] = 1;
  for (int i = 2; i <= n; i++) {
    long long res = 0;
    for (int j = 0; j < k; j++) {
      long long l, r;
      l = max(0ll, i - segments[j].second);
      r = max(0ll, i - segments[j].first);
      res += dpsum[r];
      res %= mod;
      res += mod - dpsum[l - 1];
      res %= mod;
    }
    dp[i] = res;
    dpsum[i] = dpsum[i - 1] + dp[i];
    dpsum[i] %= mod;
  }
  long long ans = dp[n];
  cout << ans << "\n";
  ;
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long q, testcase = 1;
  if (multicase) {
    cin >> q;
  } else {
    q = 1;
  }
  while (q--) {
    solve();
    testcase++;
  }
  return 0;
}
