#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
void solve(set<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 (auto c : coins) {
      if (i - (c) >= 0) {
        count[i] += count[i - c];
        count[i] = count[i] % mod;
      }
    }
  }
  printf("%lld\n", count[n]);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, k;
  scanf("%lld %lld", &n, &k);
  vector<long long> v;
  vector<vector<long long>> vec;
  for (int i = 0; i < k; i++) {
    long long l, r;
    scanf("%lld %lld", &l, &r);
    vector<long long> temp(r - l + 1);
    long long st = l;
    std::iota(temp.begin(), temp.end(), st);
    vec.push_back(temp);
  }
  set<long long> s;
  for (long long i = 0; i < vec.size(); i++) {
    for (long long j = 0; j < vec[i].size(); j++) {
      s.insert(vec[i][j]);
    }
  }
  solve(s, n);
}
