#include <bits/stdc++.h>
using namespace std;
const long long N = 2e6 + 5;
const long long mod = 998244353;
long long ans[N];
long long s[N];
long long l[N], r[N];
long long n;
long long k;
signed main() {
  cin >> n >> k;
  for (long long i = 1; i <= k; i++) {
    cin >> l[i] >> r[i];
  }
  ans[1] = 1;
  for (long long i = 2; i <= n; i++)
    for (long long j = 1; j <= k; j++) {
      for (long long z = l[j]; z <= r[j]; z++)
        ans[i] += ans[i - z], ans[i] %= mod;
    }
  cout << ans[n] << endl;
}
