#include <bits/stdc++.h>
using namespace std;
const long long int mex = 2 * (1e5) + 5, p = 998244353;
long long int n, k, x, y;
vector<long long int> v;
long long int func(long long int i, long long int dp[]) {
  if (i > n) return 0;
  if (dp[i] != -1) return dp[i];
  if (i == n) return 1;
  dp[i] = 0;
  for (auto it : v)
    if (i + it <= n) dp[i] = (dp[i] + func(i + it, dp)) % p;
  return dp[i];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  long long int dp[n + 1];
  for (long long int i = 0; i <= n; i++) {
    dp[i] = -1;
  }
  while (k--) {
    cin >> x >> y;
    for (long long int i = x; i <= y; i++) v.push_back(i);
  }
  cout << func(1, dp);
}
