#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long countWays(vector<int> arr, int m, int N) {
  long long count[N + 1];
  memset(count, 0, sizeof(count));
  count[0] = 1;
  for (long long i = 1; i <= N; i++)
    for (long long j = 0; j < m; j++)
      if (i >= arr[j]) count[i] += (count[i - arr[j]]) % 998244353;
  return count[N] % 998244353;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  int* s = new int[10000000];
  int k;
  cin >> n >> k;
  vector<pair<int, int> > segments;
  vector<int> unions;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    segments.push_back(make_pair(l, r));
  }
  for (int i = segments[0].first; i <= segments[0].second; i++)
    unions.push_back(i);
  for (int i = 1; i < k; i++) {
    int l = unions.size();
    for (int j = segments[i].first; j <= segments[i].second; j++) {
      if (j < unions[0]) unions.push_back(j);
      if (j > unions[l - 1]) unions.push_back(j);
    }
    sort(unions.begin(), unions.end());
  }
  int l = unions.size();
  long long x = countWays(unions, l, n - 1);
  cout << x;
  return 0;
}
