#include <bits/stdc++.h>
using ll = long long;
const int inf = 99999999;
const ll mod = 998244353;
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> pa(k);
  for (int i = 0; i < k; i++) {
    cin >> pa[i].first >> pa[i].second;
  }
  vector<ll> dp(n + 1000, 0);
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      for (int v = pa[j].first; v <= pa[j].second; v++) {
        if (i + v > n) break;
        dp[i + v] += dp[i];
        dp[i + v] %= mod;
      }
    }
  }
  dp[n] %= mod;
  cout << dp[n] << endl;
  return 0;
}
