#include <bits/stdc++.h>
using namespace std;
int dp[200001];
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> x;
  for (int i = 0; i < (k); i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) x.push_back(j);
  }
  sort(x.begin(), x.end());
  dp[0] = 0;
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    if (dp[i] == 0) continue;
    for (auto p : x) {
      int now = i + p;
      if (now <= n) {
        long long tmp = (long long)dp[now];
        tmp += (long long)dp[i];
        tmp %= 998244353;
        dp[now] = (int)tmp;
      } else
        continue;
    }
  }
  cout << dp[n];
}
