#include <bits/stdc++.h>
using namespace std;
long long data[200010];
struct Tree {
  long long sum;
  long long lazy;
};
Tree tree[200010 * 4];
void build(int node, int low, int high) {
  if (low == high) {
    tree[node].sum = data[low];
    tree[node].lazy = 0;
    return;
  }
  int left = node * 2;
  int right = left + 1;
  int mid = (low + high) >> 1;
  build(left, low, mid);
  build(right, mid + 1, high);
  tree[node].sum = tree[left].sum + tree[right].sum;
  tree[node].lazy = 0;
}
void update(int node, int low, int high, int lr, int hr, long long val) {
  if (tree[node].lazy) {
    tree[node].sum += (high - low + 1) * tree[node].lazy;
    if (low != high) {
      tree[node * 2].lazy += tree[node].lazy;
      tree[node * 2 + 1].lazy += tree[node].lazy;
    }
    tree[node].lazy = 0;
  }
  if (low > hr || high < lr) return;
  if (low >= lr && high <= hr) {
    tree[node].sum += (high - low + 1) * val;
    if (low != high) {
      tree[node * 2].lazy += val;
      tree[node * 2 + 1].lazy += val;
    }
    return;
  }
  int left = node * 2;
  int right = left + 1;
  int mid = (low + high) >> 1;
  update(left, low, mid, lr, hr, val);
  update(right, mid + 1, high, lr, hr, val);
  tree[node].sum = tree[left].sum + tree[right].sum;
}
long long query(int node, int low, int high, int lr, int hr) {
  if (low > hr || high < lr) return 0;
  if (tree[node].lazy) {
    tree[node].sum += (high - low + 1) * tree[node].lazy;
    if (low != high) {
      tree[node * 2].lazy += tree[node].lazy;
      tree[node * 2 + 1].lazy += tree[node].lazy;
    }
    tree[node].lazy = 0;
  }
  if (low >= lr && high <= hr) {
    return tree[node].sum;
  }
  int left = node * 2;
  int right = left + 1;
  int mid = (low + high) >> 1;
  long long p = query(left, low, mid, lr, hr);
  p += query(right, mid + 1, high, lr, hr);
  return p;
}
long long l[11], r[11];
int main() {
  long long i, j, n, m, k;
  scanf("%lld %lld", &n, &k);
  for (i = 0; i < k; i++) scanf("%lld %lld", &l[i], &r[i]);
  data[n] = 1;
  build(1, 1, n);
  for (i = n; i > 1; i--) {
    long long val = query(1, 1, n, i, i);
    for (j = 0; j <= k; j++) {
      if (i - l[j] < 1) continue;
      long long lft = max(1LL, i - r[j]), rght = i - l[j];
      update(1, 1, n, lft, rght, val);
    }
  }
  long long res = query(1, 1, n, 1, 1);
  printf("%lld\n", res % 998244353);
  return 0;
}
