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