#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
int inf = 0x3f3f3f3f;
long long infl = 0x3f3f3f3f3f3f3f3fLL;
long double infd = 1.0 / 0.0;
const long long MOD = 998244353;
const long double pi = 2 * acos(0.0);
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long n;
  cin >> n;
  long long k;
  cin >> k;
  vector<long long> v;
  for (int i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    v.push_back(x);
    v.push_back(y);
  }
  sort((v).begin(), (v).end());
  v.erase(unique((v).begin(), (v).end()), v.end());
  vector<long long> dp(n + 1);
  for (int i = 0; i < n + 1; i++) dp[i] = 0;
  sort((v).begin(), (v).end());
  dp[1] = 1;
  for (long long i = 2; i <= n; i++) {
    long long x;
    long long z = 0;
    for (int j = 0; j < (int)v.size(); j++) {
      x = v[j];
      if (i - x < 0) continue;
      z = (z + dp[i - x]) % MOD;
    }
    dp[i] = (z + MOD) % MOD;
  }
  cout << dp[n];
  return 0;
}
