#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
long long int cal(vector<long long int> &memo, vector<long long int> &v,
                  long long int n, long long int c) {
  if (c == n) {
    return 1;
  }
  if (c > n) return 0;
  if (memo[c] != -1) return memo[c];
  long long int sum = 0;
  for (long long int i : v) sum = (sum + cal(memo, v, n, c + i)) % mod;
  return memo[c] = sum;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, k, a, b;
  cin >> n >> k;
  set<long long int> s;
  for (long long int i = 0; i <= k - 1; i++) {
    cin >> a >> b;
    for (int j = a; j <= b; j++) s.insert(j);
  }
  vector<long long int> v(s.begin(), s.end());
  vector<long long int> memo(n, -1);
  cout << cal(memo, v, n, 1) << " ";
  return 0;
}
