#include <bits/stdc++.h>
using namespace std;
using ll = __int128_t;
ll dp[1000005] = {0};
pair<int, int> p[10];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    cin >> p[i].first >> p[i].second;
  }
  ll cur = 1;
  for (int i = 1; i <= n; ++i) {
    cur += dp[i];
    for (int j = 0; j < k; ++j) {
      if (i + p[j].first <= n) {
        dp[i + p[j].first] += cur;
        if (i + p[j].second + 1 <= n) dp[i + p[j].second + 1] -= cur;
      }
    }
  }
  cout << int(cur % 998244353);
}
