#include <bits/stdc++.h>
using namespace std;
const int inf = 1001001001;
const long long mod = 998244353;
int main() {
  long long n, k;
  cin >> n >> k;
  vector<pair<int, int>> s(0);
  for (int i = 0; i < (k); i++) {
    int l, r;
    cin >> l >> r;
    s.push_back({l, r});
  }
  static long long dp[2000000] = {0};
  dp[0] = 1;
  for (int i = 0; i < (n); i++) {
    for (auto p : s) {
      for (int j = p.first; j <= p.second; j++) {
        dp[i + j] += dp[i];
        dp[i + j] %= mod;
      }
    }
  }
  cout << dp[n - 1] << endl;
}
