#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const long long INFL = 1e17;
const int MOD = 998244353;
int n, k;
vector<int> s;
vector<long long> dp(200001, 0);
vector<bool> done(200001, false);
long long dfs(int n, long long sum) {
  if (done[n]) return dp[n];
  for (int i = 0; i < int(s.size()); i++) {
    int next = n - s[i];
    if (next < 1)
      break;
    else {
      dp[next] = dfs(next, sum);
      sum = (sum + dp[next]) % MOD;
      done[next] = true;
    }
  }
  return sum;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) s.push_back(j);
  }
  sort(s.begin(), s.end());
  done[1] = true;
  dp[1] = 1;
  long long ans = 0;
  ans = dfs(n, 0);
  cout << ans << endl;
  return 0;
}
