#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
map<long long, long long> mp;
vector<long long> dp(1e5 + 1, 0);
long long moo = 998244353;
long long power(long long x, long long y, long long p) {
  int res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void func(long long x) {
  if (x < 0) dp[x] = 0;
  if (x == 0) dp[x] = 1;
  if (x > 0) {
    for (long long i = 1; i <= x; i++) {
      if (mp[i] > 0) {
        if (dp[x - i] == -1) func(x - i);
        dp[x] = ((dp[x] % moo) + (dp[x - i] % moo)) % moo;
      }
    }
  }
}
void solve() {
  long long n, k;
  cin >> n >> k;
  long long x, y;
  for (long long i = 0; i < k; i++) {
    cin >> x >> y;
    for (long long j = x; j <= y; j++) mp[j]++;
  }
  dp[1] = 1;
  for (long long i = 2; i <= n; i++) {
    for (long long j = 1; j < i; j++) {
      if (mp[i - j] > 0) dp[i] = ((dp[i] % moo) + (dp[j] % moo)) % moo;
    }
  }
  cout << dp[n];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
