#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int INF = 1e10;
const ll mod = 998244353;
int main() {
  ll n, k, x, y;
  cin >> n >> k;
  vector<ll> a;
  for (ll i = 0; i < (k); ++i) {
    cin >> x >> y;
    for (int j = x; j <= y; j++) {
      a.emplace_back(j);
    }
  }
  sort(a.begin(), a.end());
  vector<ll> dp(2010000, 0);
  dp[0] = 1;
  for (ll i = 0; i < (n); ++i) {
    if (dp[i] == 0) continue;
    for (auto au : a) {
      if (n >= i + au) {
        dp[i + au] += dp[i];
        dp[i + au] %= mod;
      }
    }
  }
  cout << dp[n - 1] << endl;
}
