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