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