#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int l, r;
  vector<long long> dp(n + 1, 0);
  vector<pair<int, int>> v;
  for (int j = 0; j < k; j++) {
    cin >> l >> r;
    v.push_back({l, r});
  }
  dp[0] = 1;
  ;
  dp[1] = 1;
  sort(v.begin(), v.end());
  for (int i = 2; i <= n; i++) {
    for (auto x : v) {
      int e = 0;
      for (int j = x.first; j <= x.second; j++) {
        if (j >= i) {
          e = 1;
          break;
        } else {
          dp[i] = (dp[i] + dp[i - j]) % (long long)(998244353);
        }
      }
      if (e == 1) break;
    }
  }
  cout << dp[n] << endl;
}
