#include <bits/stdc++.h>
using namespace std;
int N, K;
vector<int> d;
int cnt[200005];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> K;
  for (int i = 0; i < K; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      d.emplace_back(j);
    }
  }
  cnt[1] = 1;
  for (int i = 1; i <= N; i++) {
    for (auto j : d) {
      if (i > j) {
        cnt[i] += cnt[i - j];
        cnt[i] %= 998244353;
      }
    }
  }
  cout << cnt[N] << '\n';
  return 0;
}
