#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> dp(n, 0), l(k), r(k);
  vector<vector<int>> xxx(k, vector<int>(n, 0));
  for (int i = 0; i < (k); i++) {
    cin >> l[i] >> r[i];
  }
  dp[0] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < (k); j++) {
      if (l[j] == r[j] && i - l[j] >= 0)
        xxx[j][i] = dp[i - l[j]];
      else if (i - l[j] >= 0 && i - r[j] <= 0)
        xxx[j][i] = dp[i - l[j]] + xxx[j][i - 1];
      else if (i - l[j] >= 0 && i - r[j] >= 0)
        xxx[j][i] = xxx[j][i - 1] - dp[i - r[j] - 1] + dp[i - l[j]];
      xxx[j][i] %= 998244353;
      dp[i] += xxx[j][i];
      dp[i] %= 998244353;
      (dp[i] + 998244353) % 998244353;
    }
  }
  cout << (dp[n - 1] + 998244353) % 998244353 << endl;
}
