#include <bits/stdc++.h>
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using namespace std;
const ll mod = 998244353;
const int N = 2e5 + 5;
void solve() {
  vector<int> s;
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      s.push_back(j);
    }
  }
  vector<int> dp(n);
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    for (int& j : s) {
      if (i + j < n) {
        dp[i + j] += dp[i];
        dp[i + j] %= mod;
      }
    }
  }
  cout << dp[n - 1];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
