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