#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll MOD = 998244353;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<vector<ll>> lr(n, vector<ll>(2));
  queue<ll> q;
  for (ll i = 0; i < (ll)(k); i++) {
    cin >> lr[i][0] >> lr[i][1];
  }
  vector<int> s(n);
  int h = 0;
  for (ll i = 0; i < (ll)(k); i++) {
    for (int j = lr[i][0]; j <= lr[i][1]; j++) {
      s[h] = j;
      h++;
    }
  }
  vector<ll> a(n, 0);
  a[0] = 1;
  for (int i = 1; i < n; i++) {
    for (ll j = 0; j < (ll)(h); j++) {
      if (i - s[j] >= 0) a[i] += a[i - s[j]];
      a[i] %= MOD;
    }
  }
  cout << a[n - 1] << endl;
}
