#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
const long long MOD = 1000000007;
const long long FMOD = 998244353;
long long dp[200005];
long long n, k;
map<long long, long long> mp1;
long long solve(long long start, vector<long long> &v) {
  if (start > n) {
    return 0;
  }
  if (start == n) {
    return 1;
  }
  if (dp[start] != -1) return dp[start];
  long long ans = 0;
  long long size = v.size();
  for (long long i = 0; i < size; i++) {
    ans = (ans % FMOD + solve(start + v[i], v) % FMOD) % FMOD;
  }
  return dp[start] = ans;
}
void solve() {
  cin >> n >> k;
  set<long long> st;
  for (long long i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    for (long long j = x; j <= y; j++) st.insert(j);
  }
  vector<long long> v;
  for (auto x : st) v.push_back(x);
  memset(dp, -1, sizeof dp);
  cout << solve(1, v) << endl;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
