#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int mod = 998244353;
int dp[N] = {};
int L[20] = {}, R[20] = {};
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) cin >> L[i] >> R[i];
  dp[1] = 1;
  for (int i = 2; i <= n; i++)
    for (int j = 1; j <= m; j++)
      for (int k = max(1, i - R[j]); k <= i - L[j]; k++)
        dp[i] = (dp[i] + dp[k]) % mod;
  cout << dp[n] << '\n';
  return 0;
}
