#include <bits/stdc++.h>
using namespace std;
auto clk = clock();
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a;
  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    for (long long i = l; i < r + 1; i++) {
      a.push_back(i);
    }
  }
  vector<long long> reachable(n);
  reachable[0] = 1;
  for (long long i = 0; i < n; i++) {
    if (reachable[i] != 0) {
      for (long long j = 0; j < a.size(); j++) {
        if (i + a[j] < n) (reachable[i + a[j]] += reachable[i]) %= 998244353;
      }
    }
  }
  cout << reachable[n - 1] % 998244353 << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(8);
  long long t = 1;
  while (t--) solve();
  return 0;
}
