#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  long long int mod = 998244353;
  long long int target, temp;
  cin >> target >> temp;
  vector<long long int> c;
  for (long long int i = 0; i < temp; i++) {
    long long int a, b;
    cin >> a >> b;
    for (long long int j = a; j <= b; j++) {
      c.push_back(j);
    }
  }
  long long int n = c.size();
  target -= 1;
  vector<long long int> dp(target + 1, 0);
  dp[0] = 1;
  for (long long int i = 1; i <= target; i++) {
    for (long long int j = 0; j < n; j++) {
      if (i - c[j] >= 0) {
        (dp[i] += dp[i - c[j]]) %= mod;
      }
    }
  }
  cout << dp[target] << "\n";
}
