#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
inline int add(int a, int b) {
  a += b;
  if (a >= mod)
    return (a - mod);
  else
    return a;
}
int Ways(vector<int> arr, int m, int N) {
  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] = add(count[i], count[i - arr[j]]);
  return count[N] % mod;
}
void solve() {
  int n, k, l, r;
  cin >> n >> k;
  set<int> s;
  vector<int> pres;
  for (int i = 1; i <= k; i++) {
    cin >> l >> r;
    for (int j = l; j <= r; j++) pres.push_back(j);
  }
  int ans = Ways(pres, pres.size(), n - 1);
  cout << ans;
}
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
