#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
void debug(vector<int> &arr) {
  int n = arr.size();
  for (int(i) = 0; (i) < (n); (i)++) {
    cout << arr.at(i) << endl;
  }
}
void debug(vector<vector<int>> &board) {
  int h = board.size();
  int w = board.at(0).size();
  for (int(i) = 0; (i) < (h); (i)++) {
    for (int(j) = 0; (j) < (w); (j)++) {
      cout << board.at(i).at(j) << " ";
    }
    cout << endl;
  }
}
void debug(vector<vector<long long>> &board) {
  int h = board.size();
  int w = board.at(0).size();
  for (int(i) = 0; (i) < (h); (i)++) {
    for (int(j) = 0; (j) < (w); (j)++) {
      cout << board.at(i).at(j) << " ";
    }
    cout << endl;
  }
}
void debug(vector<string> &board) {
  int h = board.size();
  for (int(i) = 0; (i) < (h); (i)++) {
    cout << board.at(i) << endl;
  }
  return;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
int main() {
  long long dp[200001];
  long long n;
  cin >> n;
  long long k;
  cin >> k;
  vector<long long> s;
  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    for (long long j = l; j <= r; j++) {
      s.push_back(j);
    }
  }
  long long mod = 998244353;
  dp[1] = 1;
  long long ss = s.size();
  for (long long i = 2; i <= n; i++) {
    for (long long j = 0; j < ss; j++) {
      if (i - s[j] <= 0) continue;
      dp[i] += dp[i - s[j]];
    }
  }
  dp[n] %= mod;
  cout << dp[n] << endl;
  return 0;
}
