#include <bits/stdc++.h>
using namespace std;
long long bit[2 * 100005];
long long qr(int l, int r) { return (bit[r] - bit[max(0, l - 1)]) % 998244353; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  pair<int, int> arr[k];
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    arr[i].first = l;
    arr[i].second = r;
  }
  sort(arr, arr + k);
  long long b[n + 1];
  memset(b, 0, sizeof(b));
  b[1] = 1;
  bit[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      if (i - 1 < arr[j].first)
        break;
      else if (i - 1 <= arr[j].second) {
        b[i] = (b[i] + qr(1, i - arr[j].first)) % 998244353;
        break;
      } else {
        b[i] = (b[i] + qr(i - arr[j].second, i - arr[j].first)) % 998244353;
      }
    }
    bit[i] = (b[i] + bit[i - 1]) % 998244353;
  }
  cout << b[n] % 998244353 << endl;
  return 0;
}
