#include <bits/stdc++.h>
using namespace std;
const int N = 3e5;
long long dp[N];
int main() {
  int i = 0, j = 0, cs = 0, in;
  int n, k;
  cin >> n >> k;
  vector<int> v;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = a; j <= b; j++) v.push_back(j);
  }
  dp[1] = 1;
  long long mod = 998244353;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < v.size(); j++) {
      if (i - v[j] > 0) dp[i] += dp[i - v[j]], dp[i] %= mod;
    }
  }
  cout << dp[n] << "\n";
  return 0;
}
