#include <bits/stdc++.h>
using namespace std;
long long dp[200005];
vector<long long> v;
long long func(long long n) {
  if (n == 1) return 1;
  if (dp[n] != -1) return dp[n];
  long long ans = 0;
  for (auto x : v) {
    if (n >= x + 1) {
      ans = (ans + func(n - x)) % 998244353;
    }
  }
  return dp[n] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n, k, l, r;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    for (long long x = l; x <= r; x++) {
      v.push_back(x);
    }
  }
  memset(dp, -1, sizeof(dp));
  cout << func(n);
  return 0;
}
