#include <bits/stdc++.h>
using namespace std;
typedef vector<pair<long long int, long long int>> vec_p;
const long long int MOD = 998244353;
const long long int LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
vector<long long int> S;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int N, K;
  cin >> N >> K;
  for (long long int i = 0; i < (long long int)(K); i++) {
    long long int a, b;
    cin >> a >> b;
    for (long long int i = a; i <= b; i++) {
      S.push_back(i);
    }
  }
  long long int s = S.size();
  long long int dp[N + 1];
  for (long long int i = 0; i < (long long int)(N + 1); i++) {
    dp[i] = 0;
  }
  for (long long int i = 0; i < (long long int)(s); i++) {
    dp[S.at(i)]++;
  }
  for (long long int i = 1; i <= (long long int)(N + 1); i++) {
    for (long long int j = 0; j < (long long int)(s); j++) {
      if ((i - S.at(j)) >= 0) {
        dp[i] += dp[i - S.at(j)];
        dp[i] %= MOD;
      }
    }
  }
  cout << dp[N - 1] << endl;
}
