#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long max(long long a, long long b) { return (a > b ? a : b); }
long long min(long long a, long long b) { return (a < b ? a : b); }
long long dx[4] = {1, 0, -1, 0};
long long dy[4] = {0, 1, 0, -1};
void yes_or_no(long long x) {
  if (x)
    cout << "Yes\n";
  else
    cout << "No\n";
}
const long long mod = 998244353;
void solve_test() {
  long long ans = 0;
  string s;
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> seg(k);
  for (int i = 0; i < k; i++) cin >> seg[i].first >> seg[i].second;
  vector<long long> a;
  for (auto i : seg) {
    a.push_back(i.first);
    a.push_back(i.second);
    __f("i.first, i.second", i.first, i.second);
  }
  set<long long> st;
  for (auto i : a) st.insert(i);
  long long mx = -1;
  for (long long i : a) mx = max(mx, i);
  vector<long long> dp(n + 1, 0);
  dp[1] = 1;
  for (long long i = 1; i <= n; i++) {
    for (auto j : st) {
      if (i - j >= 0) dp[i] = (dp[i] + dp[i - j]) % mod;
    }
  }
  ans = dp[n];
  cout << ans << "\n";
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  solve_test();
  return 0;
}
