#include <bits/stdc++.h>
using namespace std;
int n, k;
const int N = 2e5 + 10, mod = 998244353;
set<pair<int, int>> v;
long long int dp[N];
void solve() {
  cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    int l, r;
    cin >> l >> r;
    v.insert({l, r});
  }
  dp[n] = 1;
  for (int i = n; i >= 1; i--)
    for (auto j : v)
      for (int x = j.first; x <= j.second; ++x)
        if (i - x >= 1 && dp[i]) dp[i - x] = (dp[i - x] + dp[i]) % mod;
  cout << dp[1] << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
