#include <bits/stdc++.h>
using namespace std;
int n, k;
pair<int, int> a[100];
long long int dp[200000 + 1];
long long int rec(int s) {
  if (dp[s] != -1) return dp[s];
  if (s == n) return 1;
  long long int ans = 0;
  for (int i = 0; i < k; i++)
    for (int j = a[i].first; j <= a[i].second; j++)
      if (s + j <= n) ans = (ans + rec(s + j)) % 998244353;
  dp[s] = ans;
  return ans;
}
int main() {
  for (int i = 0; i <= 200000; i++) dp[i] = -1;
  cin >> n >> k;
  for (int i = 0; i < k; i++) cin >> a[i].first >> a[i].second;
  cout << rec(1);
  return 0;
}
