#include <bits/stdc++.h>
using namespace std;
class Leaping_Tak {
 private:
  long long n, k;
  vector<long long> a;
  const long long M = 998244353;
  vector<long long> dp;

 public:
  Leaping_Tak(vector<pair<long long, long long> > _a, long long _n) {
    for (auto x : _a) {
      for (long long i = x.first; i <= x.second; i++) a.push_back(i);
    }
    n = _n;
    k = a.size();
    dp.resize(n + 1, -1);
  }
  long long mod(long long x) {
    x %= M;
    return (x + M) % M;
  }
  long long solve(long long id) {
    if (id >= n) return (id == n);
    long long &tmp = dp[id];
    if (tmp != -1) return tmp;
    tmp = 0;
    for (long long x : a) tmp = mod(tmp + solve(id + x));
    return tmp;
  }
};
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long> > a(k);
  for (auto &p : a) cin >> p.first >> p.second;
  Leaping_Tak lt(a, n);
  cout << lt.solve(1) << '\n';
}
