#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int n, k;
vector<int> l, r;
int main(void) {
  cin >> n >> k;
  l.assign(k, 0);
  r.assign(k, 0);
  for (int i = 0; i < k; i++) cin >> l[i] >> r[i];
  vector<long long> mem(n + 1, 0);
  mem[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      for (int x = l[j]; x <= r[j]; x++) {
        if (i + x > n) break;
        (mem[i + x] += mem[i]) %= mod;
      }
    }
  }
  cout << mem[n] << endl;
}
