#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long INF = 1e+14;
vector<int> s;
vector<long long> dp(200010, -1);
long long leaping_tak(int n) {
  long long res = 0;
  if (dp[n] != -1) return dp[n];
  if (n == 1) {
    return 1;
  }
  int l = s.size();
  for (int i = 0; i < l; i++) {
    int next = n - s[i];
    if (next > 0) {
      res += leaping_tak(next);
      res %= mod;
    }
  }
  return dp[n] = res;
}
int main() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = 0; j < b - a + 1; j++) {
      s.push_back(a + j);
    }
  }
  long long ans = leaping_tak(n);
  cout << ans << endl;
}
