#include <bits/stdc++.h>
using namespace std;
inline void get(vector<long long> &arr, long long n) {
  long long a;
  for (long long i = 0; i < n; i++) {
    cin >> a;
    arr.push_back(a);
  }
}
inline void print(vector<long long> &arr, long long n) {
  for (long long i = 0; i < n; i++) cout << arr[i] << " ";
  cout << "\n";
  ;
}
bool comp(pair<long long, long long> &a, pair<long long, long long> &b) {
  return (a.first < b.first);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  t = 1;
  const long long mod = 998244353;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    vector<pair<long long, long long>> v;
    for (long long i = (0); i < (k); ++i) {
      long long a, b;
      cin >> a >> b;
      if (a >= n) continue;
      v.push_back({a, b});
    }
    if (v.size() == 0) {
      cout << 0 << "\n";
      ;
      return (0);
    }
    sort(v.begin(), v.end(), comp);
    vector<long long> steps;
    for (long long i = (0); i < ((long long)v.size()); ++i) {
      for (long long j = (v[i].first); j < (v[i].second + 1); ++j) {
        steps.push_back(j);
      }
    }
    if ((long long)steps.size() == 0) {
      cout << 0 << "\n";
      ;
      return (0);
    }
    vector<long long> dp(n + 1, 0);
    dp[1] = 1;
    for (long long i = (1); i < (n + 1); ++i) {
      for (auto jump : steps) {
        if (i + jump <= n) {
          dp[i + jump] = (dp[i + jump] % mod + dp[i] % mod) % mod;
        } else {
          break;
        }
      }
    }
    cout << dp[n] % mod << "\n";
    ;
  }
  return 0;
}
