#include <bits/stdc++.h>
using namespace std;
const unsigned long long modu = 998244353;
vector<pair<int, int> > v;
unsigned long long dp[200005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end());
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    if (dp[i] || i == 1) {
      for (int j = 0; j < k; j++) {
        for (int p = v[j].first; p <= v[j].second && i + p <= n; p++) {
          dp[i + p] += dp[i];
          dp[i + p] %= modu;
        }
      }
    }
  }
  cout << dp[n] % modu << endl;
  return 0;
}
