#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;
const int MAXN = 2e5 + 10;
int n, k;
vector<int> second;
int dp[MAXN];
int dfs(int v = 1) {
  if (~dp[v]) return dp[v];
  int res = (v == n);
  for (auto to : second)
    if (v + to <= n) {
      res += dfs(v + to);
      if (res >= MOD2) res -= MOD2;
    }
  return dp[v] = res;
}
void solve() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> k;
  for (int i = 1; i <= k; ++i) {
    int l, r;
    cin >> l >> r;
    while (l <= r) second.push_back(l++);
  }
  sort(second.begin(), second.end());
  second.erase(unique(second.begin(), second.end()), second.end());
  cout << dfs();
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  while (T--) solve(), cout << '\n';
  return 0;
}
