#include <bits/stdc++.h>
using namespace std;
int n, k;
pair<int, int> g[11];
int dp[400001];
int main() {
  cin >> n >> k;
  int i, j, p;
  for (i = 1; i <= k; ++i) cin >> g[i].first >> g[i].second;
  dp[1] = 1;
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= k; ++j) {
      for (p = g[j].first; p <= g[j].second && i + p <= n; p++) {
        dp[i + p] = (dp[i + p] + dp[i]) % 998244353;
      }
    }
  }
  cout << dp[n];
}
