#include <bits/stdc++.h>
using namespace std;
struct Node {
  int data;
  struct Node* left;
  struct Node* right;
  Node(int x) {
    data = x;
    left = NULL;
    right = NULL;
  }
};
long long modpow(long long a, long long n) {
  long long m = 1e9 + 7;
  if (n == 0) return 1;
  long long y = modpow(a, n / 2) % m;
  if (n % 2 == 0) return (y * y) % m;
  return (((y * y) % m) * a) % m;
}
long long dp[200005];
long long pro(int i, vector<int>& v) {
  if (i == 1) return 1;
  if (i <= 0) return 0;
  if (dp[i] != -1) return dp[i];
  long long m = 998244353;
  long long ans = 0;
  for (int j = 0; j < v.size(); j++) {
    if (v[j] >= i) break;
    ans += pro(i - v[j], v);
    ans = ans % m;
  }
  return dp[i] = ans;
}
int main() {
  int t = 1;
  while (t--) {
    int n, k;
    cin >> n >> k;
    vector<int> v;
    for (int i = 0; i < k; i++) {
      int x, y;
      cin >> x >> y;
      for (long long j = x; j <= y; j++) v.push_back(j);
    }
    sort(v.begin(), v.end());
    memset(dp, -1, sizeof(dp));
    cout << pro(n, v) << endl;
  }
  return 0;
}
