#include <bits/stdc++.h>
using namespace std;
long long dp[12][200005];
void inp(long long a[], long long n) {
  for (int i = 0; i < n; i++) cin >> a[i];
}
void out(long long a[], long long n) {
  for (int i = 0; i < n; i++) cout << a[i] << " ";
  cout << endl;
}
int z = 998244353;
bool cmp(pair<int, int> f, pair<int, int> s) { return (f.first < s.first); }
void solve() {
  long long n, k;
  cin >> n >> k;
  long long ans = 0;
  vector<pair<long long, long long>> ranges;
  pair<long long, long long> p;
  for (int i = 1; i <= k; i++) {
    cin >> p.first >> p.second;
    ranges.push_back(p);
  }
  sort(ranges.begin(), ranges.end(), cmp);
  for (int i = 0; i <= n; i++)
    for (int j = 0; j < k + 1; j++) dp[j][i] = 0;
  for (int i = 0; i < k + 1; i++) dp[i][n] = 0;
  dp[0][n] = 1;
  for (int i = n - 1; i >= 1; i--) {
    for (int j = 0; j < k; j++) {
      long long left = ranges[j].first;
      long long right = ranges[j].second;
      if (i + left <= n) {
        if ((i + left) != n) {
          dp[j][i] = dp[j][i + 1];
          for (int l = 0; l < k; l++) {
            dp[j][i] = (dp[j][i] + dp[l][i + left]) % z;
          }
        } else
          dp[j][i] = 1;
      } else
        break;
      if (i + right < n) {
        for (int l = 0; l < k; l++) {
          dp[j][i] = (dp[j][i] - dp[l][i + right + 1]) % z;
        }
      } else
        break;
    }
  }
  long long sum = 0;
  for (int i = 0; i < k; i++) sum = (sum + dp[i][1]) % z;
  cout << sum << endl;
  cout << endl;
}
int main() {
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
