#include <bits/stdc++.h>
using namespace std;
const long long Mod = 998244353;
const long long INF = 999999999999999999;
const long long NN = (long long)(1e6 + 5);
long long min(long long x, long long y) {
  if (x < y) return x;
  return y;
}
long long max(long long x, long long y) {
  if (x > y) return x;
  return y;
}
long long power(long long x, unsigned long long y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return power(x, y / 2) * power(x, y / 2);
  else
    return x * power(x, y / 2) * power(x, y / 2);
}
long long hcf(long long a, long long b) {
  if (b == 0) return a;
  return hcf(b, a % b);
}
long long N;
vector<long long> v;
vector<long long> dp(NN, -1);
long long f(long long sum) {
  if (sum == 0) return 1;
  long long &ans = dp[sum];
  if (ans != -1) return ans;
  long long x = 0;
  for (long long i = 0; i < N; i++) {
    if (v[i] <= sum)
      x += f(sum - v[i]), x %= Mod;
    else
      break;
  }
  return ans = x % Mod;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long TT = 1;
  while (TT--) {
    long long n, k, l, r, i, j;
    cin >> n >> k;
    set<long long> s;
    for (i = 0; i < k; i++) {
      cin >> l >> r;
      for (j = l; j <= r; j++) s.insert(j);
    }
    for (auto u : s) v.push_back(u);
    N = v.size();
    cout << f(n - 1);
  }
}
