#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
  long long mod = 998244353;
  long long n, k;
  cin >> n >> k;
  vector<long long> dp(n + 1, 0);
  dp[1] = 1;
  vector<pair<long long, long long>> vp(k);
  for (long long i = 0; i < k; i++) {
    cin >> vp[i].first >> vp[i].second;
    if (vp[i].first > vp[i].second) swap(vp[i].first, vp[i].second);
  }
  sort(vp.begin(), vp.end());
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j < k; j++) {
      for (long long d = vp[j].first; d <= vp[j].second; d++) {
        if (i >= d) {
          dp[i] = (dp[i] + dp[i - d]) % mod;
        }
      }
    }
  }
  cout << dp[n] << endl;
}
