#include <bits/stdc++.h>
using namespace std;
vector<int> dx = {-1, 1, 0, 0};
vector<int> dy = {0, 0, -1, 1};
const int maxn = 2e5 + 5;
set<int> s;
int dp[maxn];
int n, k;
pair<int, int> p[10];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  int i, j;
  for (i = 0; i < k; i++) {
    cin >> p[i].first >> p[i].second;
  }
  for (i = 0; i < k; i++) {
    for (j = p[i].first; j <= p[i].second; ++j) {
      s.insert(j);
    }
  }
  dp[0] = 0;
  dp[1] = 1;
  for (i = 2; i <= n; ++i) {
    for (int x : s) {
      if (x > i) {
        break;
      }
      dp[i] += (dp[i - x]) % 998244353;
      dp[i] %= 998244353;
    }
  }
  cout << dp[n] % 998244353 << "\n";
  return 0;
}
