#include <bits/stdc++.h>
using namespace std;
long long int MOD = 998244353;
long long int helper(vector<long long int> &arr, long long int n,
                     long long int sum, long long int ans,
                     vector<long long int> &dp) {
  if (sum == 0) {
    ans++;
    return ans % MOD;
  }
  if (dp[sum] != -1) return dp[sum];
  long long int temp = 0;
  for (long long int i = 0; i < n; i++) {
    if (arr[i] <= sum) {
      temp += helper(arr, n, sum - arr[i], ans, dp);
      temp %= MOD;
    } else
      break;
  }
  dp[sum] = temp;
  return temp % MOD;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, k;
  cin >> n >> k;
  map<long long int, long long int> m;
  for (long long int i = 0; i < k; i++) {
    long long int x, y;
    cin >> x >> y;
    for (long long int j = x; j <= y; j++) m[j]++;
  }
  vector<long long int> v;
  for (auto it : m) v.push_back(it.first);
  vector<long long int> dp(n, -1);
  long long int s = v.size();
  cout << helper(v, s, n - 1, 0, dp) << '\n';
  return 0;
}
