#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
const int mod = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  vector<vector<int>> LR(N, vector<int>(2, 0));
  vector<int> st;
  for (int i = 0; i < (K); ++i) {
    cin >> LR[i][0] >> LR[i][1];
    for (int j = LR[i][0]; j <= LR[i][1]; ++j) {
      st.emplace_back(j);
    }
  }
  sort(st.begin(), st.end());
  ll ans = 0;
  vector<ll> mp(N + 1.0);
  mp[1] = 1;
  for (int i = 1; i < N; ++i) {
    for (auto e : st) {
      if (i + e <= N) {
        mp[i + e] = (mp[i + e] + mp[i]) % mod;
      } else {
        break;
      }
    }
  }
  cout << mp[N] << endl;
  return 0;
}
