#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
int main() {
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> t, ans(n + 100000, {0, 0});
  for (long long _ = 0; _ < k; ++_) {
    pair<long long, long long> p;
    cin >> p.first >> p.second;
    t.push_back(p);
  }
  long long f = 0;
  for (long long i = 1; i <= n; i++) {
    f += ans[i].first;
    if (i == 1 || f > 0) {
      for (auto p : t) {
        ans[i + p.first].first =
            ans[i + p.first].first + (i == 1 ? 1 : f) % mod;
        ans[i + p.second].second =
            ans[i + p.second].second + (i == 1 ? 1 : f) % mod;
      }
    }
    f -= ans[i].second;
  }
  long long aaaa = 0;
  for (long long i = 1; i < n; i++) {
    aaaa = ((aaaa + ans[i].first) % mod - (ans[i].second)) % mod;
  }
  aaaa = (aaaa + ans[n].first) % mod;
  cout << aaaa;
}
