#include <bits/stdc++.h>
using namespace std;
long long countWays(vector<int> arr, int m, int N) {
  long long count[N + 1];
  for (int i = 0; i <= N; ++i) count[i] = 0;
  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] % 998244353;
}
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> vec;
  for (int i = 0; i < k; ++i) {
    int x, y;
    cin >> x >> y;
    for (int j = x; j <= y; ++j) vec.push_back(j);
  }
  long long ans = countWays(vec, vec.size(), n - 1);
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
