#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int mod = 998244353;
const int iinf = 1e9 + 10;
const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};
const int mxN = 2e5;
long long dp[mxN + 1];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> v;
  while (k--) {
    int a, b;
    cin >> a >> b;
    for (int i = a; i <= b; i++) {
      if (i <= n - 1) v.push_back(i);
    }
  }
  dp[0] = 1;
  for (int i = 0; i <= n - 1; i++) {
    for (int j = 0; j < (int)v.size(); j++) {
      if (i - v[j] >= 0) {
        dp[i] = (dp[i] + dp[i - v[j]]) % mod;
      }
    }
  }
  cout << dp[n - 1];
}
