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