#include <bits/stdc++.h>
using namespace std;
long long n;
int k;
long long dp[200005];
long long mod = 998244353;
vector<int> arr;
long long fun(int pos) {
  if (pos == 0) {
    return 1LL;
  }
  if (pos < 0) return 0;
  if (dp[pos] != -1) return dp[pos];
  long long res = 0;
  for (int i = 0; i < arr.size(); i++) {
    if ((pos - arr[i]) < 0) break;
    res += fun(pos - arr[i]);
    if (res >= mod) res = res % mod;
  }
  return dp[pos] = res;
}
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  unordered_map<int, int> mp;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    while (x <= y) {
      if (mp[x] == 0) {
        mp[x] = 1;
        arr.push_back(x);
      }
      x++;
    }
  }
  sort(arr.begin(), arr.end());
  memset(dp, -1, sizeof dp);
  cout << fun(n) << endl;
  return 0;
}
