#include <bits/stdc++.h>
using namespace std;
set<int> s;
int n, mod = 998244353, dp[200200];
int Solve(int i) {
  if (i > n) return 0;
  if (i == n) return 1;
  int &ret = dp[i];
  if (ret + 1) return ret;
  ret = 0;
  for (int x : s) ret = (ret + Solve(i + x) % mod) % mod;
  return ret % mod;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int k;
  cin >> n >> k;
  while (k--) {
    int x, y;
    cin >> x;
    cin >> y;
    for (int xx = x; xx <= y; xx++) s.insert(xx);
  }
  memset(dp, -1, sizeof dp);
  cout << Solve(1);
  return 0;
}
