#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
void solve() {
  int n, k;
  cin >> n >> k;
  int i, a, b, j, p;
  vector<pair<int, int>> possible;
  vector<int> dp(n + 1, 0);
  for (i = 0; i < k; i++) {
    cin >> a >> b;
    possible.push_back(make_pair(a, b));
  }
  dp[0] = 0;
  dp[1] = 1;
  for (i = 0; i <= n; i++) {
    for (j = 0; j < k; j++) {
      for (p = possible[j].first; p <= possible[j].second; p++) {
        if (i > p) {
          dp[i] = (dp[i] % mod + dp[i - p] % mod) % mod;
        }
      }
    }
  }
  cout << dp[n] << endl;
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
