#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  int* l = new int[k]{0};
  int* r = new int[k]{0};
  for (int i = 0; i < k; i++) cin >> l[i] >> r[i];
  int* s = new int[k]{0};
  int dp[] = {0}, temp;
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      if (i - l[j] >= 1) {
        temp = dp[i - l[j]] % 998244353;
        s[j] %= 998244353;
        s[j] = (s[j] + temp) % 998244353;
      }
      if (i - r[j] - 1 >= 1) {
        temp = dp[i - r[j] - 1] % 998244353;
        s[j] %= 998244353;
        s[j] = (s[j] - temp) % 998244353;
      }
      dp[i] %= 998244353;
      s[j] %= 998244353;
      dp[i] = (dp[i] + s[j]) % 998244353;
    }
  }
  cout << dp[n];
  return 0;
}
