#include <bits/stdc++.h>
using namespace std;
int n, k, i, j;
int main() {
  cin >> n >> k;
  int l[10], r[10];
  vector<long long> dp;
  vector<int> s;
  for (i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
    for (j = l[i]; j <= r[i]; j++) {
      s.push_back(j);
    }
  }
  dp.push_back(0);
  dp.push_back(1);
  for (i = 2; i <= n; i++) {
    dp.push_back(0);
    for (j = 0; j < s.size(); j++) {
      if (i - s[j] >= 1) {
        dp[i] += dp[i - s[j]];
        dp[i] %= 998244353;
      }
    }
  }
  cout << dp[n];
  return 0;
}
