#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int N = 2 * 1e5 + 10;
int dp[N];
unordered_map<int, int> m;
int main() {
  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int> > a(k);
  vector<int> d;
  for (int i = 0; i < k; i++) {
    cin >> a[i].first >> a[i].second;
    int x = a[i].first;
    int y = a[i].second;
    for (int j = x; j <= y; j++) {
      d.push_back(j);
    }
  }
  sort(d.begin(), d.end());
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < d.size(); j++) {
      if (i - d[j] <= 0) break;
      if (dp[i - d[j]] > 0) dp[i] = (dp[i] + dp[i - d[j]]) % mod;
    }
  }
  cout << dp[n] << endl;
  return 0;
}
