#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  int n, k;
  cin >> n >> k;
  vector<int> ans(n + 1);
  set<int> moves;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    for (int j = x; j <= y; j++) moves.insert(j);
  }
  ans[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (auto j : moves) {
      if (i + j <= n) {
        ans[i + j] = (ans[i + j] + ans[i]) % MOD;
      }
    }
  }
  cout << ans[n] << "\n";
  return 0;
}
