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