#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int mpow(int base, int exp);
long long randGen(long long lower, long long upper) {
  return (rand() % (upper - lower + 1)) + lower;
}
long long dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
long long count(long long amount, long long sm, vector<long long>& coins,
                vector<long long>& dp) {
  if (sm > amount) return 0;
  if (dp[sm] != -1) return dp[sm];
  if (sm == amount) return dp[sm] = 1;
  int ans = 0;
  for (int i = 0; i < coins.size(); i++) {
    ans += count(amount, sm + coins[i], coins, dp);
    ans %= MOD;
  }
  return dp[sm] = ans % MOD;
}
void test_case() {
  long long n, k;
  cin >> n >> k;
  vector<long long> st, dp(n + 1, -1);
  for (int i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    for (long long j = x; j <= y; j++) {
      st.push_back(j);
    }
  }
  cout << count(n, 1, st, dp) << endl;
}
int main() {
  int t = 1;
  while (t-- > 0) {
    test_case();
  }
  return 0;
}
int mpow(int base, int exp) {
  base %= MOD;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((long long)result * base) % MOD;
    base = ((long long)base * base) % MOD;
    exp >>= 1;
  }
  return result;
}
