#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long ar[N];
set<int> st;
long long dp[2 * N];
long long func(int cur) {
  if (dp[cur] != -1) return dp[cur];
  auto it2 = st.upper_bound(cur - 1);
  long long val = 0;
  for (auto it = st.begin();; it++) {
    if (it == it2) break;
    int jump = *it;
    if (dp[cur - jump] == -1) dp[cur - jump] = func(cur - jump);
    val = (val + dp[cur - jump]) % 998244353;
  }
  return val;
}
void solve() {
  int n, k;
  cin >> n >> k;
  pair<int, int> ar[k + 1];
  for (int i = 1; i < k + 1; i++) {
    cin >> ar[i].first >> ar[i].second;
    for (int j = ar[i].first; j < ar[i].second + 1; j++) st.insert(j);
  }
  memset(dp, -1, sizeof(dp));
  dp[1] = 1;
  cout << func(n);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
    cout << "\n";
  }
}
