#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;
const ll mod = 998244353;
ll dp[200010];
int main() {
  int n, k, l, r;
  cin >> n >> k;
  dp[0] = 1LL;
  for (int i = 0; i < (int)(n - 1); i++) dp[i + 1] = 0;
  set<int> s;
  for (int i = 0; i < (int)(k); i++) {
    cin >> l >> r;
    s.insert(l);
    s.insert(r);
  }
  for (int i = 0; i < (int)(n); i++) {
    for (auto p : s) {
      if (n < i + p) continue;
      dp[i + p] = dp[i] + dp[i + p];
      dp[i + p] %= mod;
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
