#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
void dfs(int n, int now, int ans, set<int> S) {
  for (int s : S) {
    if (now + s == n) {
      ans++;
      ans %= MOD;
      break;
    }
    if (now + s > n) break;
    dfs(n, now + s, ans, S);
  }
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> segment(k);
  set<int> s;
  for (int i = 0; i < (k); i++) {
    cin >> segment[i].first >> segment[i].second;
    for (int j = segment[i].first; j <= segment[i].second; ++j) {
      s.insert(j);
    }
  }
  long long ans = 0;
  dfs(n, 1, ans, s);
  cout << ans << endl;
}
