#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  vector<pair<long long int, long long int> > v;
  long long int n, k;
  cin >> n >> k;
  for (long long int i = 0; i < k; i++) {
    long long int a, b;
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  vector<long long int> s(n + 2, 0);
  s[n] = 1;
  for (int i = n - 1; i >= 1; i--) {
    s[i] = s[i + 1];
    s[i] %= mod;
    for (int j = 0; j < k; j++) {
      long long int l = v[j].first + i, r = v[j].second + i;
      r = min(n, r);
      if (l <= n) s[i] += (s[l] - s[r + 1]);
      s[i] %= mod;
    }
    s[i] %= mod;
  }
  s[1] += mod;
  s[1] -= s[2];
  s[1] %= mod;
  cout << s[1] << endl;
}
