#include <bits/stdc++.h>
using namespace std;
long long n, k, ind = 1;
const int maxn = 2e5 + 100;
long long dp[maxn];
long long l[15], r[15], a[maxn];
void uni() {
  for (int i = 1; i <= k; i++) {
    for (int j = l[i]; j <= r[i]; j++) a[ind] = j, ind++;
  }
}
void display() {
  for (int i = 1; i <= ind - 1; i++) cout << a[i] << ' ';
  cout << endl;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= k; i++) cin >> l[i] >> r[i];
  dp[1] = 1;
  uni();
  sort(a + 1, a + ind - 1);
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= ind - 1; j++) {
      if (i - a[j] >= 1)
        dp[i] += dp[i - a[j]];
      else
        break;
    }
  }
  return cout << dp[n] % 998244353 << endl, 0;
}
