#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> jumps;
  for (int i = 0; i < k; ++i) {
    int a, b;
    cin >> a >> b;
    for (int j = a; j <= b; ++j) {
      jumps.push_back(j);
    }
  }
  vector<long long> dp(n + 1);
  dp[1] = 1;
  for (long long i = 2; i <= n; ++i) {
    for (auto x : jumps) {
      if (i - x >= 1) {
        dp[i] += dp[i - x];
        dp[i] %= MOD;
      }
    }
  }
  cout << dp[n];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long tc = 1;
  while (tc--) {
    solve();
    cout << '\n';
  }
  return 0;
}
