#include <bits/stdc++.h>
using namespace std;
unsigned int n, k, l, r;
set<unsigned int> section;
unsigned int root = 0;
void go_next(unsigned int now) {
  for (auto itr = section.begin(); itr != section.end(); ++itr) {
    if (now + *itr == n) {
      root++;
      root %= 998244353;
      return;
    } else if (now + *itr < n) {
      go_next(now + *itr);
    } else {
      break;
    }
  }
  return;
}
int main() {
  scanf("%u %u", &n, &k);
  for (auto i = 0; i < k; ++i) {
    scanf("%u %u", &l, &r);
    for (unsigned int j = l; j <= r; ++j) {
      section.insert(j);
    }
  }
  go_next(1);
  printf("%u", root);
}
