#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
  long long int res = 1;
  while (b) {
    if (b & 1) {
      res = res * a;
    }
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
const long long int mod = 998244353;
vector<pair<int, int> > a;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k, l, r;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    a.push_back(make_pair(l, r));
  }
  sort(a.begin(), a.end());
  int beg = a[0].first;
  int end = a[0].second;
  vector<pair<int, int> > b;
  for (int i = 1; i < a.size(); i++) {
    if (a[i].first > end) {
      b.push_back(make_pair(beg, end));
      beg = a[i].first;
      end = a[i].second;
    } else {
      end = max(end, a[i].second);
    }
  }
  b.push_back(make_pair(beg, end));
  vector<int> jumps;
  for (int i = 0; i < b.size(); i++) {
    int j = b[i].first;
    int k = b[i].second;
    for (int p = j; p <= k; p++) {
      jumps.push_back(p);
    }
  }
  long long int dp[n + 1];
  for (int i = 0; i <= n; i++) dp[i] = 0;
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < jumps.size(); j++) {
      if (i - jumps[j] >= 0) {
        dp[i] = dp[i] + dp[i - jumps[j]];
        dp[i] %= mod;
      } else {
        break;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}
