#include <bits/stdc++.h>
using namespace std;
long long MOD = 998244353;
int main() {
  long long n, k;
  cin >> n >> k;
  queue<long long> range1;
  queue<long long> range2;
  vector<long long> dp(n + 5, 0);
  for (int i = 0; i < (int)(k); i++) {
    long long l, r;
    cin >> l >> r;
    for (long long j = l; j <= r; j++) range1.push(j);
  }
  dp[1] = 1;
  for (long long i = 1; i < n; i++) {
    if (i % 2) {
      while (!range1.empty()) {
        long long d = range1.front();
        if (i + d <= n) {
          dp[i + d] += dp[i];
          dp[i + d] %= MOD;
          range2.push(d);
        }
        range1.pop();
      }
    } else {
      while (!range2.empty()) {
        long long d = range2.front();
        if (i + d <= n) {
          dp[i + d] += dp[i];
          dp[i + d] %= MOD;
          range1.push(d);
        }
        range2.pop();
      }
    }
  }
  cout << dp[n] % MOD << endl;
  return 0;
}
