#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long inf64 = 1e18;
const int mod = 998244353;
const int N = 2e5 + 10;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, k;
  cin >> n >> k;
  vector<int> steps;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i < r + 1; i++) steps.push_back(i);
  }
  sort((steps).begin(), (steps).end());
  vector<long long> dp(n);
  dp[0] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < (int)steps.size(); j++) {
      if (steps[j] <= i)
        dp[i] = (dp[i] + dp[i - steps[j]]) % mod;
      else
        break;
    }
  }
  cout << dp[n - 1];
}
