#include <bits/stdc++.h>
using namespace std;
long long dp[200001];
unordered_map<int, int> m;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  dp[1] = 1;
  vector<pair<int, int> > steps(k + 1);
  for (int i = 1; i <= (k); i++) {
    cin >> steps[i].first >> steps[i].second;
  }
  if (n == 1) {
    cout << 0;
    return 0;
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < (int)steps.size(); j++) {
      for (int k = steps[j].first; k <= steps[j].second; k++) {
        if (i - k < 0) break;
        dp[i] = (dp[i] + dp[i - k]) % 998244353;
      }
    }
  }
  cout << dp[n] << endl;
}
