#include <bits/stdc++.h>
using namespace std;
vector<int> visited(200001, 0);
vector<int> memo(200001, 0);
long long dp(int var, vector<int>& arr) {
  if (visited[var]) return memo[var];
  visited[var] = 1;
  for (int nums : arr) {
    if (nums <= var)
      memo[var] = (memo[var] + dp(var - nums, arr)) % long long(998244353);
    else
      break;
  }
  return memo[var];
}
int main() {
  visited[0] = 1;
  memo[0] = 1;
  int n, k;
  cin >> n >> k;
  vector<int> arr;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = a; j <= b; j++) {
      arr.push_back(j);
    }
  }
  sort(arr.begin(), arr.end());
  long long ans = dp(n - 1, arr);
  cout << ans;
  return 0;
}
