#include <bits/stdc++.h>
using namespace std;
const int mx = 6e6 + 5;
long long mod = 998244353;
long long dp[mx];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> v;
  for (long long i = 0; i < k; ++i) {
    long long am, ak;
    cin >> am >> ak;
    for (long long jk = am; jk <= ak; ++jk) {
      v.push_back(jk);
    }
  }
  dp[1] = 1;
  for (long long i = 1; i < n; ++i) {
    for (long long jk = 0; jk < v.size(); ++jk) {
      dp[v[jk] + i] = ((dp[i] + dp[v[jk] + i]) % mod);
    }
  }
  cout << (dp[n]) % mod << '\n';
}
