#include <bits/stdc++.h>
const int maxn = 2e5 + 5;
const int mod = 998244353;
using namespace std;
long long dp[maxn];
vector<int> v;
int n, k, x, y;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d%d", &x, &y);
    for (int j = x; j <= y; j++) v.push_back(j);
  }
  dp[1] = 1;
  sort(v.begin(), v.end());
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < v.size(); j++) {
      int t = v[j];
      if (i - t >= 1)
        dp[i] = (dp[i] + dp[i - t]) % mod;
      else
        break;
    }
  }
  printf("%lld\n", dp[n]);
}
