#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> s;
  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());
  s.erase(unique(s.begin(), s.end()), s.end());
  vector<long long> dp(n + 1);
  dp[1] = 1;
  for (int i = 1; i < n; ++i) {
    if (dp[i] != 0) {
      for (int j = 0; j < s.size(); ++j) {
        if (i + s[j] <= n) {
          dp[i + s[j]] += dp[i];
          dp[i + s[j]] %= MOD;
        } else
          break;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}
