#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int q = 1;
  vector<int> c;
  while (q--) {
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < k; i++) {
      int l, r;
      cin >> l >> r;
      for (int i = l; i <= r; i++) c.push_back(i);
    }
    int size = c.size();
    long long target = n - 1;
    vector<long long> dp(target + 1, 0);
    dp[0] = 1;
    for (int i = 1; i <= target; i++)
      for (int j = 0; j < size; j++)
        if (i - c[j] >= 0) (dp[i] += dp[i - c[j]]) %= mod;
    cout << dp[target];
  }
  return 0;
}
