#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<pair<int, int>> pos;
vector<int> dp;
const int M = 998244353;
int solve(int cpos) {
  if (cpos == n) return 1;
  if (cpos > n) return 0;
  if (dp[cpos] != -1) return dp[cpos];
  int ans = 0;
  for (auto &i : pos) {
    for (int j = i.first; j <= i.second; j++) {
      if (cpos + j > n)
        break;
      else
        ans = (ans + solve(cpos + j)) % M;
    }
  }
  return dp[cpos] = ans;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  cin >> n >> k;
  pos.resize(k);
  for (auto &i : pos) cin >> i.first >> i.second;
  sort(pos.begin(), pos.end());
  dp.resize(n + 1, -1);
  cout << solve(1) << "\n";
}
