#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
long long int dp[1000001];
long long int tsum(long long int cur, vector<long long int> a) {
  if (cur == 1)
    return 1;
  else if (cur <= 0)
    return 0;
  else if (dp[cur] != 0)
    return dp[cur] % mod;
  else {
    long long int x = 0;
    for (int i = 0; i < a.size(); i++) {
      if (cur - a[i] <= 0) break;
      x = (x % mod + tsum(cur - a[i], a) % mod) % mod;
    }
    dp[cur] = x % mod;
    return dp[cur];
  }
}
int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  long long int n, k;
  cin >> n >> k;
  vector<long long int> a;
  memset(dp, 0, sizeof dp);
  for (long long int i = 0; i < k; i++) {
    long long int x1, x2;
    cin >> x1 >> x2;
    for (long long int j = x1; j <= x2; j++) a.push_back(j);
  }
  sort(a.begin(), a.end());
  long long int ans = tsum(n, a);
  cout << ans << endl;
  return 0;
}
