#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T;
  T = 1;
  while (T--) {
    long long i, n, k;
    cin >> n >> k;
    vector<long long> v;
    for (i = 0; i < k; i++) {
      long long x, y;
      cin >> x >> y;
      for (long long j = x; j <= y; j++) v.push_back(j);
    }
    sort(v.begin(), v.end());
    long long dp[n + 1];
    memset(dp, 0, sizeof(dp));
    for (i = 1; i <= n; i++) {
      if (i == 1)
        dp[i] = 1;
      else {
        for (long long j = 0; j < (long long)(v.size()); j++) {
          if (v[j] < i)
            dp[i] = (dp[i] % 998244353 + dp[i - v[j]] % 998244353) % 998244353;
          else
            break;
        }
      }
    }
    cout << dp[n] << "\n";
  }
  return 0;
}
