#include <bits/stdc++.h>
using namespace std;
vector<int> setter;
vector<int> dp(200010, -1);
int dpi(int n) {
  if (n <= 0) {
    return 0;
  }
  if (dp[n] != -1) {
    return dp[n];
  }
  if (n == 1) {
    return dp[n] = 1;
  } else {
    long long int ans = 0;
    for (auto i : setter) {
      ans += dpi(n - i);
      ans %= 998244353;
    }
    return dp[n] = ans;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++) {
      setter.push_back(i);
    }
  }
  cout << dpi(n) << endl;
}
