#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int Mod = 998244353;
map<string, int> mp;
int n, m, T, t;
stringstream ss;
string s;
vector<int> G[N];
int a[N], b[N];
long long ret;
void BFS(int sum, int r) {
  queue<int> qu;
  qu.push(sum);
  while (qu.size()) {
    sum = qu.front();
    qu.pop();
    for (int i = 0; i <= r; i++) {
      if (sum + b[i] < n) {
        qu.push(sum + b[i]);
      } else if (sum + b[i] == n)
        ret++;
    }
  }
}
int main() {
  int k;
  scanf("%d %d", &n, &k);
  int r = -1;
  for (int i = 0, r, l; i < k; i++) {
    cin >> l >> r;
    for (int i = l; i <= r; i++) {
      a[i] = 1;
    }
  }
  for (int i = 1; i <= N; i++) {
    if (a[i] == 1) b[++r] = i;
  }
  BFS(1, r);
  cout << ret % Mod << endl;
  return 0;
}
