#include <bits/stdc++.h>
using namespace std;
long long int n, k;
long long int cnt = 0;
std::vector<long long int> s;
const long long int mod = 998244353;
long long int save[200001];
inline void dfs(const long long int index, long long int& tmpcnt) {
  for (int i = 0; i < s.size(); i++) {
    const unsigned long long int next = index + (long long int)s[i];
    if (next == n) {
      cnt++;
      tmpcnt++;
      if (cnt == mod) cnt = 0;
      if (tmpcnt == mod) tmpcnt = 0;
      break;
    } else if (next > n) {
      break;
    }
    if (save[next] == -1) {
      dfs(next, tmpcnt);
    } else {
      cnt += save[next];
      tmpcnt += save[next];
    }
  }
  save[index] = tmpcnt;
}
int main() {
  for (int i = 0; i < 200000; i++) {
    save[i] = -1;
  }
  cin >> n >> k;
  std::vector<int> l(k), r(k);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  std::sort(l.begin(), l.end());
  std::sort(r.begin(), r.end());
  for (int i = 0; i < k; i++) {
    for (int j = l[i]; j <= r[i]; j++) {
      s.push_back(j);
    }
  }
  long long int tmp = 0;
  dfs(1, tmp);
  cout << cnt % mod << endl;
  return 0;
}
