#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 998244353;
void add(ll &a, ll b) {
  a = (a + b) % MOD;
  a = (a + MOD) % MOD;
}
int main() {
  int n, k;
  cin >> n >> k;
  set<int> s;
  vector<ll> dp(n + 1, 0);
  dp[1] = 1;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      s.insert(j);
    }
  }
  for (int i = 1; i < n; i++) {
    if (dp[i] == 0) continue;
    for (int ad : s) {
      if (i + ad <= n) {
        dp[i + ad] = (dp[i + ad] + dp[i]) % MOD;
      }
    }
  }
  cout << (dp[n] + MOD) % MOD << endl;
}
