#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
const int MOD = 998244353;
const int N = 4e5 + 5;
int n, k;
int l[11], r[11];
long long cnt = 0;
long long al[N], ar[N];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &l[i], &r[i]);
  }
  memset(al, 0, sizeof(al));
  memset(ar, 0, sizeof(ar));
  al[1] = 1;
  ar[2] = 1;
  for (int i = 1; i <= n; i++) {
    cnt += al[i];
    cnt -= ar[i];
    if (cnt >= MOD) cnt -= MOD;
    if (cnt != 0) {
      for (int j = 0; j < k; j++) {
        int x = l[j], y = r[j];
        al[i + x] += cnt;
        if (al[i + x] >= MOD) al[i + x] -= MOD;
        ar[i + y + 1] += cnt;
        if (ar[i + y + 1] >= MOD) ar[i + y + 1] -= MOD;
      }
    }
  }
  printf("%d", cnt);
  return 0;
}
