#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 998244353;
int ans = 0;
void walk(int n, vector<int> vec) {
  if (n == 0) {
    ans++;
    ans %= mod;
  }
  for (int x : vec) {
    if (x > n) break;
    walk(n - x, vec);
  }
}
int main(void) {
  int n, k;
  cin >> n >> k;
  vector<int> vec;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) vec.push_back(j);
  }
  sort(vec.begin(), vec.end());
  walk(n - 1, vec);
  cout << ans << endl;
  return 0;
}
