#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> vec, dp(n, 0);
  for (int i = 0; i < (k); i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      vec.push_back(j);
    }
  }
  dp[0] = 1;
  for (int i = 0; i < (n); i++) {
    for (auto x : vec) {
      if (i - x >= 0) {
        dp[i] += dp[i - x];
        dp[i] %= 998244353;
      }
    }
  }
  cout << dp[n - 1] << endl;
}
