#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000007;
const long long mod = 998244353;
vector<long long> memo;
vector<long long> s;
long long dp(long long i) {
  if (i < 0) return 0;
  if (i == 0) return 1;
  if (memo[i] != -1) return memo[i];
  long long aaa = 0;
  for (auto val : s) {
    aaa += dp(i - val);
    aaa %= mod;
  }
  memo[i] = aaa;
  return aaa;
}
int main() {
  long long K, N;
  cin >> N >> K;
  memo = vector<long long>(N, -1);
  for (int i = 0; i < (K); ++i) {
    long long l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      s.push_back(j);
    }
  }
  cout << dp(N - 1) << endl;
  return 0;
}
