#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> arrfront(n + 1, 0);
  vector<pair<long long int, long long int>> v;
  unordered_map<long long int, long long int> s;
  for (long long int i = 0; i < k; i++) {
    long long int a, b;
    cin >> a >> b;
    v.emplace_back(make_pair(a, b));
  }
  vector<long long int> arrback(n + 1, 0);
  sort(v.begin(), v.end());
  long long int ans = 0;
  for (long long int i = 1; i < n; i++) {
    if (arrfront[i] == 0) {
      if (i != 1) {
        continue;
      } else {
        arrfront[i] = 1;
      }
    }
    for (long long int j = 0; j < v.size(); j++) {
      if (i + v[j].first > n) {
        break;
      }
      for (long long int k = v[j].first; k < v[j].second + 1; k++) {
        if (i + k > n) {
          break;
        }
        arrfront[i + k] = arrfront[i + k] % m;
        arrfront[i + k] = (arrfront[i + k] % m + arrfront[i] % m) % m;
        arrfront[i + k] = arrfront[i + k] % m;
      }
    }
  }
  cout << (arrfront[n] % m);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
