#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int n, k, l, r;
vector<pair<int, int> > vec;
long long dp[200001];
struct segtree {
  int size;
  vector<long long> sums;
  void init(int n) {
    size = 1;
    while (size < n) size *= 2;
    sums.assign(2 * size, 0LL);
  }
  void build(vector<long long> &a, int x, int lx, int rx) {
    if (rx - lx == 1) {
      if (lx < (int)a.size()) sums[x] = a[lx];
      return;
    }
    int m = (lx + rx) / 2;
    build(a, 2 * x + 1, lx, m);
    build(a, 2 * x + 2, m, rx);
    sums[x] = sums[2 * x + 1] + sums[2 * x + 2];
  }
  void build(vector<long long> &a) { build(a, 0, 0, size); }
  void set(int i, int v, int x, int lx, int rx) {
    if (rx - lx == 1) {
      sums[x] = v;
      return;
    }
    int m = (lx + rx) / 2;
    if (i < m) {
      set(i, v, 2 * x + 1, lx, m);
    } else {
      set(i, v, 2 * x + 2, m, rx);
    }
    sums[x] = sums[2 * x + 1] + sums[2 * x + 2];
  }
  void set(int i, int v) { set(i, v, 0, 0, size); }
  long long sum(int l, int r, int x, int lx, int rx) {
    if (lx >= l && rx <= r) return sums[x];
    if (lx >= r || rx <= l) return 0;
    int m = (lx + rx) / 2;
    long long s1 = sum(l, r, 2 * x + 1, lx, m);
    long long s2 = sum(l, r, 2 * x + 2, m, rx);
    return s1 + s2;
  }
  long long sum(int l, int r) { return sum(l, r, 0, 0, size); }
};
int main() {
  cin.sync_with_stdio(0);
  cin.tie();
  cin.exceptions(cin.failbit);
  long long n, k, l, r;
  cin >> n >> k;
  vector<long long> dp(n + 1);
  dp[n] = 1;
  segtree st;
  st.init(n);
  st.build(dp);
  for (int i = 1; i <= k; i++) {
    cin >> l >> r;
    vec.push_back({l, r});
  }
  for (int i = n - 1; i >= 1; i--) {
    long long ans = 0;
    for (auto &s : vec) {
      if (i + s.first <= n) {
        ans = (ans +
               st.sum(i + s.first, min(n + 1, (long long)i + s.second + 1))) %
              MOD;
      }
    }
    ans %= MOD;
    dp[i] = ans;
    st.set(i, ans);
  }
  cout << dp[1];
}
