#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 998244353;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<int> m;
  for (int i = 0; i < (int)(k); ++i) {
    int x, y;
    cin >> x >> y;
    for (int j = x; j <= y; j++) m.emplace_back(j);
  }
  sort(m.begin(), m.end());
  vector<int> dp(n + 10);
  dp[1] = 1;
  for (int i = 0; i < (int)(n); ++i) {
    for (int move : m) {
      if (move + i > n) break;
      dp[i + move] += dp[i];
      dp[i + move] %= mod;
    }
  }
  cout << dp[n] << endl;
  return 0;
}
