#include <bits/stdc++.h>
using namespace std;
const int MxN = 1e5, md = 998244353;
vector<int> s;
int n, k;
long long go() {
  vector<long long> v(n + 1, 0);
  queue<int> q;
  q.push(1);
  while (!q.empty()) {
    int f = q.front();
    q.pop();
    for (auto i : s)
      if (i + f <= n) {
        q.push(i + f);
        v[i + f] = (v[f] + 1) % md;
      }
  }
  return v[n] % md;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  int a, b;
  for (int i = 0; i < k; ++i) {
    cin >> a >> b;
    for (int i = a; i <= b; ++i) s.push_back(i);
  }
  vector<long long> dp(n + 1, 0);
  dp[1] = 1;
  for (int i = 2; i <= n; ++i)
    for (int j = 0; j < s.size(); ++j)
      if (i >= s[j]) dp[i] = (dp[i] + dp[i - s[j]]) % md;
  cout << dp[n];
}
