#include <bits/stdc++.h>
using namespace std;
long long int countWays(vector<int> arr, int m, int N) {
  long long int count[N + 1];
  memset(count, 0, sizeof(count));
  count[0] = 1;
  for (int i = 1; i <= N; i++)
    for (int j = 0; j < m; j++)
      if (i >= arr[j]) count[i] = (count[i - arr[j]] + count[i]) % 998244353;
  return count[N];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, k;
  cin >> n >> k;
  pair<int, int> p[k];
  for (int i = 0; i < k; i += 1) cin >> p[i].first >> p[i].second;
  vector<int> v;
  for (int i = 0; i < k; i += 1) {
    for (int j = p[i].first; j < p[i].second + 1; j += 1) v.push_back(j);
  }
  long long int ans = countWays(v, v.size(), n - 1);
  cout << ans << endl;
}
