#include <bits/stdc++.h>
using namespace std;
int dp[200001];
long long int solve(int i, int n, vector<int> v) {
  if (dp[i] != -1) return dp[i];
  if (i == n) return 1;
  long long int ans = 0;
  for (auto it : v)
    if ((i + it) <= n)
      ans = (ans + solve(i + it, n, v) % 998244353) % 998244353;
  return dp[i] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int T = 1, t, n, m, q, k, i, j;
  while (T--) {
    cin >> n >> k;
    for (i = 0; i < 200001; i++) dp[i] = -1;
    vector<int> vec;
    for (i = 0; i < k; i++) {
      cin >> m >> t;
      for (j = m; j < t + 1; j++) vec.push_back(j);
    }
    cout << solve(1, n, vec);
  }
}
