#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
map<long long, vector<long long>> fact;
vector<long long> dp(200005);
vector<long long> mov;
int main() {
  long long n, k;
  cin >> n >> k;
  long long i, j;
  dp[0] = 0;
  dp[1] = 1;
  long long l, r;
  for (i = 0; i < k; i++) {
    cin >> l >> r;
    for (j = l; j <= r; j++) {
      mov.push_back(j);
    }
  }
  sort(mov.begin(), mov.end());
  for (i = 2; i <= n; i++) {
    for (j = 0; j < mov.size(); j++) {
      if (i - mov[j] <= 0) {
        break;
      } else {
        dp[i] += dp[i - mov[j]];
        dp[i] = dp[i] % 998244353;
      }
    }
  }
  cout << dp[n] % 998244353 << endl;
}
