#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> d(k);
  for (int i = 0; i < (k); i++) {
    cin >> d[i].first >> d[i].second;
  }
  vector<ll> dp(n + 1);
  dp[1] = 1;
  for (int i = (2); i < (n + 1); i++) {
    for (int j = 0; j < (k); j++) {
      for (int l = (d[j].first); l < (d[j].second + 1); l++) {
        if (i - l < 1) continue;
        dp[i] = (dp[i] + dp[i - l]) % 998244353LL;
      }
    }
  }
  cout << dp[n] << endl;
}
