#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> pos;
  set<int> pres;
  while (k--) {
    int x, y;
    cin >> x >> y;
    for (int i = x; i <= y; i++) {
      if (pres.find(i) == pres.end()) {
        pos.push_back(i);
        pres.insert(i);
      }
    }
  }
  vector<long long> dp(n, 0);
  dp[0] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < pos.size(); j++) {
      int lp = i - pos[j];
      if (lp >= 0) {
        dp[i] = ((dp[i] + dp[lp]) % (long long)(998244353));
      }
    }
  }
  cout << dp[n - 1] << "\n";
  ;
}
