#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
vector<long long> sm;
vector<long long> dp(200005, -1);
long long dfs(long long rem) {
  if (rem < 0) {
    return 0;
  }
  if (rem == 0) {
    return 1;
  }
  if (dp[rem] != -1) {
    return dp[rem];
  }
  long long ret = 0;
  for (int i = 0; i < sm.size(); i++) {
    ret += dfs(rem - sm[i]);
    ret %= mod;
  }
  dp[rem] = ret;
  return ret;
}
int main() {
  long long n;
  int k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    while (l <= r) {
      sm.push_back(l++);
    }
  }
  cout << dfs(n - 1) << endl;
  return 0;
}
