#include <bits/stdc++.h>
using namespace std;
long long tree[400005], dp[200001], lazy[400005];
void build(int node, int start, int end) {
  if (start == end) {
    tree[node] = dp[start];
  } else {
    int mid = (start + end) / 2;
    build(2 * node, start, mid);
    build(2 * node + 1, mid + 1, end);
    tree[node] = (tree[2 * node] + tree[2 * node + 1]) % 998244353;
  }
}
void updateRange(int node, int start, int end, int l, int r, int val) {
  if (lazy[node] != 0) {
    tree[node] += (end - start + 1) * lazy[node];
    if (start != end) {
      lazy[node * 2] += lazy[node];
      lazy[node * 2] %= 998244353;
      lazy[node * 2 + 1] += lazy[node];
      lazy[node * 2 + 1] %= 998244353;
    }
    lazy[node] = 0;
  }
  if (start > end or start > r or end < l) return;
  if (start >= l and end <= r) {
    tree[node] += ((end - start + 1) * val) % 998244353;
    tree[node] %= 998244353;
    if (start != end) {
      lazy[node * 2] += val;
      lazy[node * 2] %= 998244353;
      lazy[node * 2 + 1] += val;
      lazy[node * 2 + 1] %= 998244353;
    }
    return;
  }
  int mid = (start + end) / 2;
  updateRange(node * 2, start, mid, l, r, val);
  updateRange(node * 2 + 1, mid + 1, end, l, r, val);
  tree[node] = (tree[node * 2] + tree[node * 2 + 1]) % 998244353;
}
int queryRange(int node, int start, int end, int l, int r) {
  if (start > end or start > r or end < l) return 0;
  if (lazy[node] != 0) {
    tree[node] += ((end - start + 1) * lazy[node]) % 998244353;
    tree[node] %= 998244353;
    if (start != end) {
      lazy[node * 2] += lazy[node];
      lazy[node * 2] %= 998244353;
      lazy[node * 2 + 1] += lazy[node];
      lazy[node * 2 + 1] %= 998244353;
    }
    lazy[node] = 0;
  }
  if (start >= l and end <= r) return tree[node];
  int mid = (start + end) / 2;
  int p1 = queryRange(node * 2, start, mid, l, r);
  int p2 = queryRange(node * 2 + 1, mid + 1, end, l, r);
  return (p1 + p2) % 998244353;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  int l[k], r[k], li = 0;
  for (int i = 0; i < k; i++) cin >> l[i] >> r[i];
  for (int i = 0; i <= n; i++) dp[i] = 0;
  dp[1] = 1;
  build(1, 1, n);
  for (int i = 1; i <= n; i++) {
    dp[i] = queryRange(1, 1, n, i, i) % 998244353;
    for (int j = 0; j < k; j++) {
      if (i + l[j] <= n)
        updateRange(1, 1, n, i + l[j], min(i + r[j], n), dp[i] % 998244353);
    }
  }
  cout << dp[n] % 998244353;
  return 0;
}
