#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
long long int dp[200200];
int main() {
  int n, i, j, k, x, y, ans, curr, temp, m;
  int tc;
  cin >> n >> k;
  dp[1] = 1;
  vector<int> v;
  for (i = 1; i <= k; i++) {
    cin >> x >> y;
    for (j = x; j <= y; j++) {
      v.push_back(j);
    }
  }
  sort(v.begin(), v.end());
  for (i = 2; i <= n; i++) {
    dp[i] = 0;
    for (auto x : v) {
      if (i - x > 0) {
        dp[i] += dp[i - x];
        dp[i] %= mod;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}
