#include <bits/stdc++.h>
using namespace std;
long long arr[1000000];
long long M = 998244353;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  vector<long long> v;
  long long i, j, k, x, y, z, n;
  cin >> n >> k;
  for (i = 0; i < k; i++) {
    cin >> x >> y;
    for (j = x; j <= y; j++) {
      v.push_back(j);
    }
  }
  sort(v.begin(), v.end());
  arr[1] = 1;
  for (i = 2; i <= n; i++) {
    x = 0;
    for (j = 0; j < v.size(); j++) {
      y = i - v[j];
      if (y <= 0) {
        break;
      }
      x = (x + arr[y]) % M;
    }
    arr[i] = x;
  }
  cout << arr[n] << endl;
}
