#include <bits/stdc++.h>
using namespace std;
long long int dp[(long long int)(1e6)];
long long int work(int x, vector<int> &a, int n) {
  if (x == n) return 1;
  if (x > n) return 0;
  if (dp[x] != -1) return dp[x];
  long long int ans = 0;
  for (int i = 0; i < a.size() && x + a[i] <= n; i++) {
    ans = (ans + work(x + a[i], a, n)) % (long long int)(998244353);
  }
  return dp[x] = ans;
}
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> s;
  while (k--) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++) s.push_back(i);
  }
  vector<int> a(s.begin(), s.end());
  sort(a.begin(), a.end());
  cout << work(1, a, n) << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    memset(dp, -1, sizeof(dp));
    solve();
  }
  return 0;
}
