#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, k;
vector<int> a;
long long int dp[(int)1e5 + 10];
long long int rec(int i) {
  if (i == n)
    return 1;
  else if (i > n)
    return 0;
  if (dp[i] != -1) return dp[i];
  long long int ans = 0;
  for (int j : a) {
    ans += rec(i + j), ans %= mod;
  }
  return dp[i] = ans;
}
void solve() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; ++j) a.push_back(j);
  }
  cout << rec(1) << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
