#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
void solve(vector<long long> coins, long long n) {
  n--;
  long long count[n + 1];
  memset(count, 0, sizeof(count));
  count[0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < coins.size(); j++) {
      if (i - (coins[j]) >= 0) {
        count[i] += count[i - coins[j]];
        count[i] = count[i] % mod;
      }
    }
  }
  cout << count[n] << endl;
}
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> v;
  for (int i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      v.push_back(j);
    }
  }
  long long m = v.size();
  vector<long long>::iterator ip;
  std::sort(v.begin(), v.end());
  ip = std::unique(v.begin(), v.begin() + m);
  v.resize(std::distance(v.begin(), ip));
  solve(v, n);
}
