#include <bits/stdc++.h>
using namespace std;
int main() {
  int mod = 998244353;
  int n, k, a, b, c;
  cin >> n >> k;
  vector<int> sum(n + 1, 0);
  vector<int> ans(n + 1, 0);
  vector<pair<int, int>> pair;
  for (int i = 0; i < (int)(k); i++) {
    cin >> a >> b;
    pair.push_back(make_pair(a, b));
  }
  sum[0] = 0;
  sum[1] = 1;
  for (int i = 0; i < (int)(n + 1); i++) {
    if (i == 0 || i == 1) continue;
    sum[i] = sum[i - 1];
    for (int j = 0; j < (int)(k); j++) {
      c = 0;
      if (pair[j].first > i) continue;
      if (pair[j].second > i) {
        ans[i] += sum[i - pair[j].first];
        ans[i] %= mod;
        sum[i] = (ans[i] + sum[i - 1]) % mod;
      } else {
        ans[i] += sum[i - (pair[j].first)] - sum[i - (pair[j].second + 1)];
        ans[i] %= mod;
        sum[i] = (ans[i] + sum[i - 1]) % mod;
      }
    }
  }
  if (ans[n] < 0) ans[n] += mod;
  cout << ans[n] << endl;
}
