#include <bits/stdc++.h>
using namespace std;
vector<long long> ok(1000001, 0);
vector<bool> vis(1000001, false);
vector<int> v;
void here(int n) {
  for (auto x : v) {
    if (n - x > 0) {
      if (vis[n - x]) {
        ok[n] += ok[n - x];
        ok[n] %= 998244353;
      } else {
        here(n - x);
        ok[n] += ok[n - x];
        ok[n] %= 998244353;
      }
    } else {
      break;
    }
  }
  vis[n] = 1;
}
void jabru() {
  vis[1] = 1;
  int n;
  cin >> n;
  int k;
  cin >> k;
  for (long long i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      v.push_back(j);
    }
  }
  sort(v.begin(), v.end());
  ok[1] = 1;
  here(n);
  cout << ok[n] << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  t = 1;
  while (t--) jabru();
  return 0;
}
