#include <bits/stdc++.h>
using namespace std;
long long int m = 998244353;
void solve() {
  long long int n, k;
  cin >> n >> k;
  vector<long long int> temp(n + 1, 0);
  vector<pair<long long int, long long int>> v;
  for (long long int i = 0; i < k; i++) {
    long long int a, b;
    cin >> a >> b;
    v.emplace_back(make_pair(a, b));
  }
  sort(v.begin(), v.end());
  long long int ans = 0;
  temp[1] = 1;
  long long int current = 0;
  for (long long int i = 1; i < n; i++) {
    current = current + temp[i];
    if (current == 0) {
      continue;
    }
    for (long long int j = 0; j < v.size(); j++) {
      long long int f = i + v[j].first;
      long long int l = i + v[j].second;
      if (f > n) {
        break;
      } else {
        temp[f] += current;
      }
      if (l + 1 > n) {
        continue;
      } else {
        temp[l + 1] -= current;
      }
    }
  }
  cout << temp[n] % m;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
