#include <bits/stdc++.h>
using namespace std;
int n, k;
int l[15], r[15];
int sum[200005], dp[200005];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= k; i++) cin >> l[i] >> r[i];
  dp[1] = 1, sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      (dp[i] += sum[max(i - l[j], 0)] - sum[max(i - r[j] - 1, 0)]) %= 998244353;
    }
    sum[i] = sum[i - 1] + dp[i];
    sum[i] %= 998244353;
  }
  cout << (dp[n] % 998244353 + 998244353) % 998244353 << endl;
}
