#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MX = 2e5 + 5;
const long long INF = 1e18;
const long double PI = acos((long double)-1);
void setIO(string name = "") {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if ((int)(name).size()) {
    freopen((name + ".in").c_str(), "r", stdin);
    freopen((name + ".out").c_str(), "w", stdout);
  }
}
int main() {
  setIO();
  long long n, k;
  cin >> n >> k;
  set<long long> uni;
  while (k--) {
    long long a, b;
    cin >> a >> b;
    for (long long i = a; i <= b; i++) uni.insert(i);
  }
  vector<long long> dp(n + 1LL, 0LL);
  dp[1] = 1;
  for (long long i = 1; i <= n; i++) {
    for (auto it : uni) {
      if (i > it) {
        dp[i] += (dp[i - it] % 998244353LL);
        dp[i] %= 998244353LL;
        dp[i] = (dp[i] + 998244353LL) % 998244353LL;
      } else
        break;
    }
  }
  cout << (dp[n] + 998244353LL) % 998244353LL;
}
